Rails 3.1.3 latest formtastic My app requires dynamic select forms, so I have models class Departure < ActiveRecord::Base has_many :airlines has_many :destinations, :through => :airlines end class Destination < ActiveRecord::Base has_many :airlines has_many :departures, :throught => airlines end class Airline < ActiveRecord::Base belongs_to :departure belongs_to :destination end And using Formtastic, <%= semantic_form_for @plan, :remote=>true do |f| %> <%= f.inputs do %> <%= f.input :departure, :collection=>Departure.find(:all, :order=>:city).collect{ |c| [c.city,c.id]}, :required=>true %> <div id="destinationCity"> <%= render :partial => ''destination'' %> </div> <div id="airlineCompany"> <%= render :partial => ''airline'' %> <======HERE!!!! </div> <%= f.action :submit, :as => :button %> <% end %> <% end %> and JavaScript is ready as well for Ajax responses. And this works if there is no partial, ''_airline.html.erb'' part! Adding the partial _airline.html.erb raises an error, <%= semantic_form_for "plan", :remote => true do |f| %> <%= f.inputs do %> <% if !@airlines.blank? %> <%= f.input :airline, :collection=>airlines.collect{ |s| [s.company,s.id]} %> <% else %> <%= f.input :airline, :collection=>[] %> <% end %> <% end %> <% end %> #error ActionView::Template::Error (undefined method `airline'' for #<Plan:0x000001037e66f8>): 3: <% if !@airlines.blank? %> 4: <%= f.input :airline, :collection=>airlines.collect{ |s| [s.company,s.id]} %> 5: <% else %> 6: <%= f.input :airline, :collection=>[] %> 7: <% end %> 8: <% end %> 9: <% end %> I don''t understand the error message because there is no method used in this particular partial. And similarly, the controller does not have such method, ''airilne''. Can anyone guess the cause of this error? Thanks soichi -- 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 https://groups.google.com/groups/opt_out.
On 13 September 2012 07:10, Soichi Ishida <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Rails 3.1.3 > latest formtastic > > > My app requires dynamic select forms, so I have models > > class Departure < ActiveRecord::Base > has_many :airlines > has_many :destinations, :through => :airlines > end > > class Destination < ActiveRecord::Base > has_many :airlines > has_many :departures, :throught => airlines > end > > class Airline < ActiveRecord::Base > belongs_to :departure > belongs_to :destination > end > > And using Formtastic, > > <%= semantic_form_for @plan, :remote=>true do |f| %> > <%= f.inputs do %> > <%= f.input :departure, > :collection=>Departure.find(:all, :order=>:city).collect{ |c| > [c.city,c.id]}, > :required=>true %> > <div id="destinationCity"> > <%= render :partial => ''destination'' %> > </div> > > <div id="airlineCompany"> > <%= render :partial => ''airline'' %> <======HERE!!!! > </div> > > <%= f.action :submit, :as => :button %> > <% end %> > <% end %> > > > and JavaScript is ready as well for Ajax responses. > > And this works if there is no partial, ''_airline.html.erb'' part! > > Adding the partial _airline.html.erb raises an error, > > <%= semantic_form_for "plan", :remote => true do |f| %> > <%= f.inputs do %> > <% if !@airlines.blank? %> > <%= f.input :airline, :collection=>airlines.collect{ |s| > [s.company,s.id]} %> > <% else %> > <%= f.input :airline, :collection=>[] %> > <% end %> > <% end %> > <% end %> > > > #error > ActionView::Template::Error (undefined method `airline'' for > #<Plan:0x000001037e66f8>): > 3: <% if !@airlines.blank? %> > 4: <%= f.input :airline, :collection=>airlines.collect{ |s| > [s.company,s.id]} %>The line above expects there to be a method airline in the Plan object that you have created the form for. Colin> 5: <% else %> > 6: <%= f.input :airline, :collection=>[] %> > 7: <% end %> > 8: <% end %> > 9: <% end %> > > I don''t understand the error message because there is no method used in > this particular partial. > And similarly, the controller does not have such method, ''airilne''. > > Can anyone guess the cause of this error? > > Thanks > > soichi > > -- > 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 https://groups.google.com/groups/opt_out. > >-- 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 https://groups.google.com/groups/opt_out.
> #error > ActionView::Template::Error (undefined method `airline'' for > #<Plan:0x000001037e66f8>): > 3: <% if !@airlines.blank? %> > 4: <%= f.input :airline, :collection=>airlines.collect{ |s| > [s.company,s.id]} %> > 5: <% else %> > 6: <%= f.input :airline, :collection=>[] %> > 7: <% end %> > 8: <% end %> > 9: <% end %>Hi Soichi, Kindly check whether ''airline'' is there in plan model or not and check if you have spelled it correctly.. Thanks, P.Angeline -- 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 https://groups.google.com/groups/opt_out.