我正在尝试将动态数量的图片添加到一个名为“组件”的元素中。环顾四周,我创建了以下代码:
组件.rb
class Component < ActiveRecord::Base
has_many :images
accepts_nested_attributes_for :images, :allow_destroy => true
end
图片.rb
class Image < ActiveRecord::Base
attr_accessible :component_id, :photo_file_size
belongs_to :component, :foreign_key => :component_id
has_attached_file :photo,
:styles => {
:thumb => "75x75>",
:small => "200x200>"
}
end
_form.html.erb
<%= form_for setup_component(@component) , :html => { :multipart => true } do |f| %>
...
<h2> PHOTOS </h2>
<% f.fields_for @component.images.build do |p| %>
<h2>Photo</h2>
<p><%= f.label :data %><br /><%= f.file_field :data %></p>
<% end %>
application_helper.rb
def setup_component(comp)
return comp.images.build if comp.images.empty?
end
因此,当我尝试形成时,出现以下错误:
undefined method `images_path'