Welcome to Working With Rails


Discussion Forums

Discuss all things Ruby on Rails with perhaps the web's most vibrant group of Ruby on Rails enthusiasts.
Multiple instances of the same model in one view
2 Posts
Multiple instances of the same model in one view

Hi folks,

I've got a problem breaking my head in a project I'm currently working on: I've got a 'medium' model, just like a file model, allowing the user to upload media into the system. The user can choose which kind of media he wants to upload and can dynamically add/remove file_fields ( i already included that ) in the 'new' view.

How can I create multiple objects of the same model coming from one view at the same time? I know how to do that with two different models in one view, but in this case i've only got this one 'media' thing.

Thank you very much in advance, Moritz

In your situation, you should generate file tag by your self instead of using Rails form helper methods. Your template file should looks like this:

 true do %>
   'media_1' # id is not necessary %>
   'media_2' %>

Notice that while accessing to params[:media] it returns an Array contains all the file objects posted from the "new" page.

Hope this will be helpful.

2 Posts
Login to add your message