RailsCasts Pro episodes are now free!

Learn more or hide this

yoavbo's Profile

GitHub User: yoavbo

Comments by

Avatar

Does anyone know how to change the file_field when dealing with nested attributes? The main table is users. each has_many images. The application works fine for uploading a single file (using carrierwave).

ruby
views/users/new.html.erb
<%= f.fields_for :images do |z| %>
<fieldset>
<p>
    <%= z.label :image_title %><br />
    <%= z.text_field :image_title %>
    <%= z.hidden_field :image_priority, :value => '1' %> 
  </p>
  <p>
    <%= z.file_field :image_location %>
  </p>
</fieldset>
<% end %>

The railscast says you should add a "multiple" option to file_Field and then "hardcode" the field name. So somthing like this:

ruby
<%= z.file_field :image_location, multiple: true, name: "images[image_location]" %>