dimanche 23 août 2015

setting parameters in create action

The requirement is to compute new params before the create action, as an after_create could create conflicts with the overall process (the class pitstop belongs_to circuit which can create multiple siblings). Thus a nested form generates parameters such as:

"circuit"=>{"pitstops_attributes"=>{"0"=>{"town"=>"Beantown", "_destroy"=>"false"}}},

Additional parameters need to be set on the pitstop child based on other submitted params. The child's controller must certainly be lacking proper syntax (what level of nesting param syntax as the controller is handling only a single create actions in a steam of multiple ones?)

@town = Town.where(['name = ?', params[:pitstop][:town]]).first
params[:pitstop][:longitude] = @town.longitude
[...]
@pitstop = Pitstop.new(params[:pitstop])

as these parameters are not processed.

undefined local variable or method `params' for

Aucun commentaire:

Enregistrer un commentaire