krn
krn

Reputation: 6815

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.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.

Upvotes: 2

Views: 508

Answers (1)

Michael De Silva
Michael De Silva

Reputation: 3818

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

Upvotes: 2

Related Questions