I have a model with an accessible attribute :days in a Rails3 app.
In my form I have a series of checkboxes which represent each day.
I’d like to pass an array of all the selected ‘days’ into my model for processing in a before_save callback.
My question is, can I construct a parameters hash without ajax/js using either standard form helpers, or if not, by defining the parameters hash for each checkbox?
The following is just a guess on how I might implement this as I’m not quite sure how rails processes the parameters in name attribute:
Something like:
<input type="checkbox" value="1" name="my_model[days][0]" id="my_model_days">
<input type="checkbox" value="2" name="my_model[days][1]" id="my_model_days">
...?
and if so will it pass an array to my model?
Any suggestions on good tutorials or threads on how to construct these parameter structures within Rails forms are welcome.
Use fields_for
http://apidock.com/rails/ActionView/Helpers/FormHelper/fields_for