部分渲染另一个控制器的视图ruby on rails

时间:2012-11-18 07:34:52

标签: ruby-on-rails twitter-bootstrap views partial-views

我在这里使用twitter Boostraps tabbable功能: http://twitter.github.com/bootstrap/components.html#navs

在此导航内容窗口中,我正在尝试渲染显示“课程”的视图。 views / courses / _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>

我正在尝试渲染它并在views / instructor / 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:语法错误,意外'=',   期待keyword_end ... tput_buffer = @output_buffer; =   local_assigns [:]; show = loca ...... ... ^   /app/views/courses/_show.html.erb:1:语法错误,意外']',   期待tSTRING_CONTENT或tSTRING_DBEG或tSTRING_DVAR或   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 个答案:

答案 0 :(得分:1)

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

相关问题