I have collection_select
in one of my views, which properly creates a HTML <select>
menu, but when I select an option it does not save in the database. In the same view I have other fields from the same db table and they save up. Here are my models:
class TrainingPart < ActiveRecord::Base
belongs_to :activity
belongs_to :training
accepts_nested_attributes_for :activity, :allow_destroy => true
end
class Activity < ActiveRecord::Base
has_many :training_parts
end
The partial is:
<div class="part">
<%= f.label :activity, "Activity" %>
<%= collection_select :training_part, :activity_id, Activity.all, :id, :name %>
<%= f.text_field :activity_id %>
<%= f.text_field :amount %>
</div>
The amount
field works fine.
EDIT: I don't use attr_accessible
in any model, so all of the fields in all tables are accessible. (reference: Rails mass assignment definition and attr_accessible use)