nested forms - Rails 4.2 saving has_and_belongs_to_many association Ids -
i have following bit of code working fine rails 4.1 protected_attributes gem (i didn't have code moved strong_parameters yet)
models/employee.rb
class employee has_and_belongs_to_many :skills attr_accessible :skill_ids, ... end
models/skill.rb
class skill has_and_belongs_to_many :employees end
i bind skills employee while updating employee view looks below
views/employees/_form.html.erb
<%= form_for @employee, |f| %> ..... <%= f.collection_select :skill_ids, skill.all, :id, :name, {}, {:multiple => true, class: 'select2 '} %> ...... <% end %>
skill_ids part of attr_accessible params worked while saving employee form. (note: doesn't require accepts_nested_attributes_for :skills set @ employee model)
rails 4.2
i in process of migrating code rails 4.2 , moving strong parameters.
i've white-listed skill_ids in employees controller , invoking on update action, :
controllers/employee_controller.rb
def update @employee = employee.find(params[:id]) @employee.update_attributes(employee_params) end private def employee_params params.require(:employee).permit(:skill_ids, .....) end
but wouldn't update skill ids employees.
can please point me has changed in rails 4.2 saving association values these?
thanks.
the issue how whitelisted param. should whitelisted array param so:
params.require(:employee).permit({:skill_ids => []}, .....)
Comments
Post a Comment