i having issues editing nested attributes. i'm getting error :
no implicit conversion of symbol integer event.rb:
class event < activerecord::base has_many :event_joins, :dependent => :destroy accepts_nested_attributes_for :event_joins end events_controller.rb :
private def event_params params.require(:event).permit(event_joins_attributes: [:duration]) end _form.html.erb :
=f.fields_for :event_joins_attributes |a| =number_field_tag 'event[event_joins_attributes][duration]' end if change params before permission
params[:event][:event_joins_attributes][:duration] = params[:event][:event_joins_attributes][:duration].to_i i have following error:
no implicit conversion of string integer i've read lot of posts nested attributes mass-assignment nothing works. here part of posts i've read.
strong-parameters-permit-all-attributes-for-nested-attributes
rails-4-strong-parameters-nested-objects
of course, don't want do
params.require(:event).permit!
you have change this
=f.fields_for :event_joins_attributes |a| =number_field_tag 'event[event_joins_attributes][duration]' end to
=f.fields_for :event_joins |a| =a.number_field :duration end so can have event_params unchanged.
imp note:
also permit :id in event_params update work correctly.
def event_params params.require(:event).permit(:id, event_joins_attributes: [:id, :duration]) end
Comments
Post a Comment