I'm following an example in the "Head First Rails" book regarding
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
But, I'm using Rails 3.0.0, and you know that "new.html.erb" for "Seats"
looks something like this:
<%= 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? %>
<h2><%= pluralize(@seat.errors.count, "error") %> prohibited this
seat from being saved:</h2>
<% @seat.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
<% 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
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.