我正在尝试用回形针将多个图像附加到一个组件上。作为本教程 http://www.tkalin.com/blog_posts/multiple-file-upload-with-rails-3-2-paperclip-html5-and-no-javascript
我有以下文件:
_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>
组件.rb
has_many :images
accepts_nested_attributes_for :images
图片.rb
class Image < ActiveRecord::Base
attr_accessible :photo_file_name
belongs_to :component
has_attached_file :photo
end
图像模型已创建为:
rails generate model image
还有回形针附件:
rails g paperclip image photo
到这个时候,我在尝试创建组件时收到以下错误:
Can't mass-assign protected attributes: image_attributes
也许我应该忘记模型和回形针调用中的某些内容?
编辑: 我应该将图像模型创建为:
rails generate model image component:references
??