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 %>
<%= render :partial => ‘destination’ %>
<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