I want to edit multiple items of my model photo in one form. I am unsure of how to correctly present and POST this with a form, as well as how to gather the items in the update action in the controller.
This is what I want:
<form> <input name="photos[1][title]" value="Photo with id 1" /> <input name="photos[2][title]" value="Photo with id 2" /> <input name="photos[3][title]" value="Custom title" /> </form>
The parameters are just an example, like I stated above: I am not sure of the best way to POST these values in this form.
In the controller I want to something like this:
@photos = Photo.find( params[photos] ) @photos.each do |photo| photo.update_attributes!(params[:photos][photo] ) end
In Rails 4, just this
<%= form_tag photos_update_path do %> <% @photos.each do |photo| %> <%= fields_for "photos[]", photo do |pf| %> <%= pf.text_field :caption %> ... other photo fields
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With