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
精彩评论