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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I forgot to mention: This is how I made the render in app/views/flights/_new_seat.html.erb <%= render ''form_seat'', :locals => {:seat => Seat.new} %> Provided again, I''m using Rails 3.0.0 Thanks. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
pass the seat variable with your render call something like this, <%= render ''form'', :locals => { :seat => @seat } %> -- Regards, T.Veerasundaravel. http://tinyurl.com/25vma7h @veerasundaravel -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Veera Sundaravel wrote:> pass the seat variable with your render call something like this, > > <%= render ''form'', :locals => { :seat => @seat } %> > > > -- > Regards, > > T.Veerasundaravel. > http://tinyurl.com/25vma7h > @veerasundaravelThanks @Veera. It actually worked when I inserted :partial => explicitly like this: <%= render :partial => ''form_seat'', :locals => {:seat => Seat.new } %> When I tried your solution: <%= render ''form_seat'', :locals => {:seat => @seat } %> I got the following: undefined local variable or method `seat'' for #<#<Class:0x515bb78>:0x515aa50> 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> Thanks. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Try using <%= render ''form'', :seat => @seat %> without locals. On Sep 22, 3:50 pm, Veera Sundaravel <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> pass the seat variable with your render call something like this, > > <%= render ''form'', :locals => { :seat => @seat } %> > > -- > Regards, > > T.Veerasundaravel.http://tinyurl.com/25vma7h > @veerasundaravel > -- > Posted viahttp://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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
tundrax wrote:> Try using <%= render ''form'', :seat => @seat %> without locals.Thanks @tundrax. I''ll try that soon. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Abder-Rahman Ali wrote:> 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. >[...] Then you''re setting yourself up for trouble. If you''re learning Rails 3, find a Rails 3 book. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
@Marnen. The issue was solved. Thanks. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.