开发者

Ruby on Rails doesn't render partial

开发者 https://www.devze.com 2023-04-04 08:21 出处:网络
jobs_controller.rb: def create @job = Job.new(params[:job]) render \"preview\" if @job.save end preview.html.haml:

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

精彩评论

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