1
votes

I'm trying to attach with paperclip a multiple number of images to a component. As this tutorial http://www.tkalin.com/blog_posts/multiple-file-upload-with-rails-3-2-paperclip-html5-and-no-javascript

I have the following files:

_form.html.erb

<div class="field">
   <%= file_field_tag('component_images_photo', multiple: true, name: "component[images_attributes][][photo]") %>
</div> 
<div class="actions">
   <%= f.submit %>
</div>

component.rb

has_many :images
accepts_nested_attributes_for :images

image.rb

class Image < ActiveRecord::Base
    attr_accessible :photo_file_name

    belongs_to :component
    has_attached_file :photo
end

The image model has been created as:

rails generate model image

And the paperclip attachment:

rails g paperclip image photo

By this time I get the following error when trying to create a component:

Can't mass-assign protected attributes: image_attributes

Maybe should I forget something in the model and paperclip calls?

EDIT: Should I created the image model as:

rails generate model image component:references

??

1

1 Answers

0
votes

You have to add attr_accessible :images_attributes to component.rb.