所以我有以下模型: 图片:
class Image < ActiveRecord::Base
has_many :product_images
has_many :products, :through => :product_images
attr_accessible :asset, :name, :description, :product_ids, :file_content_type, :is_boolean
accepts_nested_attributes_for :product_images
has_attached_file :asset
end
产品图片:
class ProductImage < ActiveRecord::Base
belongs_to :product
belongs_to :image
attr_accessible :is_thumbnail
end
和产品:
class Product < ActiveRecord::Base
has_many :images, :through => :product_images
has_many :product_images
attr_accessible :name, :description, :thumbnail, :searchTerms, :group_ids, :upload_file_ids
结尾
现在我想在图像表单上显示所有产品的复选框,然后为 is_thumbnail 属性显示另一个复选框,我已经使用 simple_fields_for 研究过,但这只会在产品已经添加时显示。有没有办法做到这一点?
<%= f.simple_fields_for(:product_images) do |builder| %>
<%= builder.input :is_thumbnail %>
<%= builder.association :products, include_blank: false %>
<% end %>