I'm following an example in the "Head First Rails" book regarding
partials.

The book seems to be using a version prior Rails 3.0.0, which I'm using.

I'm having a small issue here.

There is a "new.html.erb" for "Seats" which will be created as a partial
to be included in the "show.html.erb" page of "flights".

So, the book mentions to copy: app/views/seats/new.html.erb and paste it
to app/views/flights/_new_seat.html.erb

But, I'm using Rails 3.0.0, and you know that "new.html.erb" for "Seats"
looks something like this:

<h1>New seat</h1>

<%= render 'form' %>

<%= link_to 'Back', seats_path %>

So, there is a _form.html.erb created automatically.

What did I do?

I copied the code above and inserted it as required in
app/views/flights/_new_seat.html.erb and removing the last line.

Now came the problem when the book mentions that we make @seat in
app/views/flights/_new_seat.html.erb a LOCAL variable, as follows:

<% form_for(seat) do | f| % >

But, where is: <% form_for(@seat) do | f| % > in my case?

It is in _form.html.erb

And, here is a part of _form.html.erb (Notice @seat)

<%= form_for(@seat) do |f| %>
  <% if @seat.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@seat.errors.count, "error") %> prohibited this
seat from being saved:</h2>

      <ul>
      <% @seat.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

If I change @seat here to "seat", this I think will affect
"new.html.erb" and "edit.html.erb" of "seats".

So, I copied the file to app/views/flights/_form_seat.html.erb and
changed ALL @seat to "seat".

After running the application I get the following:

undefined local variable or method `seat' for
#<#<Class:0x4de6b78>:0x4e5b9b0>

Extracted source (around line #1):

1: <%= form_for(seat) do |f| %>
2:   <% if seat.errors.any? %>
3:     <div id="error_explanation">
4:       <h2><%= pluralize(seat.errors.count, "error") %> prohibited
this seat from being saved:</h2>

How can I solve this issue?

Sorry for my long question, but had to clarify the point.

Thanks a lot.
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to