Iteratively creating multiple file input fields in Rails

Posted by David on Stack Overflow See other posts from Stack Overflow or by David
Published on 2012-11-20T21:53:44Z Indexed on 2012/11/20 23:01 UTC
Read the original article Hit count: 199

Filed under:
|
|
|

I have a column of product views in a database (e.g. top, bottom, front, back). I'm trying to generate a series of file inputs to allow the user to upload an image for each view. This is the result I'm after:

...
<label>Top</label>
<input type="file" name="image[Top]"><br>
<label>Bottom</label>
<input type="file" name="image[Bottom]"><br>
<label>Front</label>
<input type="file" name="image[Front']"><br>
...

This is what I'm trying:

<%= views = View.order('name ASC').all.map { |view| [view.name, view.id] } %>
<%= views.each { |view| label(view); file_field('image', view) } %>

However, all this does is print out the views array a couple of times. Hopefully you Rails experts can point me in the right direction. (I apologize in advance if I'm butchering Ruby.)

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby