开发者

Ruby on Rails doesn't render partial

jobs_controller.rb:

  def create
    @job = Job.new(params[:job])
    render "preview" if @job.save
  end

preview.html.haml:

- render @job

_job.html开发者_如何学JAVA.haml:

- content_for :title, "Job preview"
%h1= @job.title

The problem: @job in the _job.html.haml file does not get rendered, even though the title variable on the first line works fine.


Replace the following in preview.html.haml

= render :partial => 'job', :locals => { :job => @job }

Then your partial will have

- content_for :title, "Job preview"
%h1= job.title

Shorter way of doing the above is

= render 'job', :job => @job
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜