I have read a number of posts about this and I'm still confused. I'm relatively new to Rails. I'm on Rails 3.2.8 and Ruby 1.9.3.
I have a form where I want to create a record for 2 different tables. It's a many-to-many relationship (logbooks can have multiple aircraft and aircraft will appear in multiple logbooks).
Here's my code:
# ----- Models ----- #
class Logbook < ActiveRecord::Base
has_and_belongs_to_many :aircrafts
accepts_nested_attributes_for :aircrafts
end
class Aircraft < ActiveRecord::Base
belongs_to :logbook
end
# ----- Logbooks Controller ----- #
def my_method
@logbook = Logbook.new
@aircraft = Aircraft.new
end
# ----- View ----- #
<%= form_for @logbook, validate: true, remote: true do |f| %>
<%= f.label :flight_date, "Flight Date" %>
<%= f.text_field :flight_date %>
...
<%= f.fields_for :aircrafts, validate: true, remote: true do |a| %>
<%= a.label :aircraft_id, "Aircraft ID" %>
<%= a.text_field :aircraft_id %>
...
<% end %>
<% end %>
The logbook fields are rendering fine, but the aircraft fields don't render.
Any ideas?