I'm likely missing something simple, but I've tried a number of things to no avail. I need to be able to edit an existing track (using ActiveAdmin) and save the record updating its exclusivity status.
I have a Tracks
model
#app/models/track.rb:
has_many :exclusivities, class_name: 'Exclusivity', dependent: :destroy
accepts_nested_attributes_for :exclusivities
attr_accessible :exclusivities_attributes
#whether or not track is exclusive [boolean]
attr_accessible :exclusive
#whether or not track is fully exclusive and should be pulled off the front end [boolean]
attr_accessible :full_exclusivity
and I just created an Exclusivity
model.
#app/models/exclusivity.rb
belongs_to :track
attr_accessible :end_date, :industry, :track_id, :notes, :staff_notes
and my form:
<%= semantic_form_for [:manage, @track], html: {data: {secondary:true}} do |f| %>
a bunch of inputs.....
<%= f.inputs "Track Exclusivity", class:'inputs align-left' do %>
<%= f.input :exclusive %>
<%= f.input :full_exclusivity,
label: "Fully Exclusive" %>
<%= f.fields_for :exclusivities do %>
<%= f.input :notes %>
<%= f.input :staff_notes %>
<%= f.input :industry %>
<%= f.input :end_date, as: :date_picker %>
<% end %>
<% end %>
When I go to edit a track, the Track attrs are there, but the nested (Exclusivity attrs) are not (I can check track's exclusive and full_exclusivity checkboxes)
I've also tried using semantic_fields_for
and f.inputs :for => exclusivities
What am I missing here?
You forgot to pass your form builder to the fields_for block.
<%= f.inputs "Track Exclusivity", class:'inputs align-left' do %>
<%= f.input :exclusive %>
<%= f.input :full_exclusivity,
label: "Fully Exclusive" %>
<%= f.fields_for :exclusivities do |ff| %>
<%= ff.input :notes %>
<%= ff.input :staff_notes %>
<%= ff.input :industry %>
<%= ff.input :end_date, as: :date_picker %>
<% end %>
<% end %>