2012-11-18 32 views
1

我使用Twitter Boostraps tabbable功能的其他控制器的视图红宝石这里找到的部分呈现: http://twitter.github.com/bootstrap/components.html#navs在轨道上

而这个导航内容的窗口内,我试图呈现一个显示“课程”的景色。在视图/场/ _show.html.erb发现这种观点是这样的:

<div class="center hero-unit"> 
<h1><%= @course.course_name %></h1> 

<%= link_to 'New Question Set',new_answer_path(:course_ID => @course.id), :class => "btn btn-large btn-primary" %> 
<%= link_to 'Launch Session!', edit_course_path, :class => "btn btn-large btn-primary" %> 
</div> 

我试图使其与在欣赏下面的代码失败/教练/ show.html.erb

<% courses.each do |c| %> 
<div class="tab-pane" id="<%=c.course_name%>"> 
<%= render :partial => 'courses/show', :locals => {@course=>c} %> 
</div> 

我得到以下错误:

/app/views/courses/_show.html.erb:1: syntax error, unexpected '=', expecting keyword_end ...tput_buffer = @output_buffer; = local_assigns[:];show = loca... ... ^ /app/views/courses/_show.html.erb:1: syntax error, unexpected ']', expecting tSTRING_CONTENT or tSTRING_DBEG or tSTRING_DVAR or tSTRING_END ...tput_buffer; = local_assigns[:];show = local_assigns[:show];... ...

说这是失败在我的课程中1线/ _show.html.erb

我的课程控制器看起来是这样的:

class CoursesController < ApplicationController 
    # GET /courses 
    # GET /courses.json 
    def index 
    @courses = Course.all 

    respond_to do |format| 
     format.html # index.html.erb 
     format.json { render :json => @courses } 
    end 
    end 

    # GET /courses/1 
    # GET /courses/1.json 
    def show 
    @course = Course.find(params[:id]) 

    respond_to do |format| 
     format.html # show.html.erb 
     format.json { render :json => @course } 
    end 
    end 

    # GET /courses/new 
    # GET /courses/new.json 
    def new 
    @course = Course.new(instructor_ID: params[:instructor_ID]) 

    respond_to do |format| 
     format.html # new.html.erb 
     format.json { render :json => @course } 
    end 
    end 

    # GET /courses/1/edit 
    def edit 
    @course = Course.find(params[:id]) 
    end 

    # POST /courses 
    # POST /courses.json 
    def create 
    @course = Course.new(params[:course]) 


    respond_to do |format| 
     if @course.save 
     format.html { redirect_to @course, :notice => 'Course was successfully created.' } 
     format.json { render :json => @course, :status => :created, :location => @course } 
     else 
     format.html { render :action => "new" } 
     format.json { render :json => @course.errors, :status => :unprocessable_entity } 
     end 
    end 
    end 

    # PUT /courses/1 
    # PUT /courses/1.json 
    def update 
    @course = Course.find(params[:id]) 

    respond_to do |format| 
     if @course.update_attributes(params[:course]) 
     format.html { redirect_to @course, :notice => 'Course was successfully updated.' } 
     format.json { head :no_content } 
     else 
     format.html { render :action => "edit" } 
     format.json { render :json => @course.errors, :status => :unprocessable_entity } 
     end 
    end 
    end 

注:我已经中省略了一些方法,如删除我的控制器,以节省空间。

任何想法?

回答

1

@course=>c将@改为冒号。

+0

当我这样做,我得到一个错误,看起来像︰undefined方法'course_name'为零:NilClass失败在页面的第2行我试图呈现 – Layla

+1

并将'@ course'更改为'course' _show.html.erb。 – cdesrosiers

+0

@cdesrosiers这样做,谢谢你 – Layla