Carrierwave multiple file uploads

317 views
Skip to first unread message

fugee ohu

unread,
Sep 13, 2019, 11:33:35 AM9/13/19
to Ruby on Rails: Talk
I read this example for the form:
<%= p.file_field :avatar, :multiple => true, name:     "post_attachments[avatar][]" %>
Why is the name argument necessary Why can't the controller just get the array from <%= p.file_field :avatar %> ?

Ariel Juodziukynas

unread,
Sep 14, 2019, 7:28:24 PM9/14/19
to rubyonra...@googlegroups.com
It adds the "[]" so the parameter is an array (if you don't add that, params[:avatar] will be only one file and not an array). I'm not sure why but the helper does not infer that, you have to be explicit on that.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/596e6ab8-a045-4bfc-86cb-252bf487f296%40googlegroups.com.

Walter Lee Davis

unread,
Sep 15, 2019, 11:36:27 AM9/15/19
to rubyonra...@googlegroups.com
My understanding is that the helpers do the "80%" solution for you -- pave the cowpaths -- but expect you to do the edge cases yourself, since you know what you are doing and what you want. Too much "magic" breeds a complacent user that expects everything to just work, all the time, which is unreasonable for the simple fact that software cannot read minds.

Walter
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAPS3bcC50WrnXZGt88HwMU_7obfY398X4guJ1uPqYDqAx%3DoCUQ%40mail.gmail.com.

Reply all
Reply to author
Forward
0 new messages