【发布时间】:2012-03-31 09:34:21
【问题描述】:
美好的一天。 有人在 Carrierwave 中以嵌套形式删除资产的解决方案吗?
型号
has_many :article_images, :dependent => :destroy
accepts_nested_attributes_for :article_images
mount_uploader :image, ImageUploader
belongs_to :article, :polymorphic => true
schema.rb
create_table "article_images", :force => true do |t|
t.string "image"
t.string "article_id"
end
create_table "articles", :force => true do |t|
t.string "title"
end
控制器
def edit
@article = Article.find(params[:id])
@article.article_images.build
end
查看
_form.html.erb
<%= f.fields_for :article_images do |article_image| %>
<% if article_image.object.new_record? %>
<%= article_image.file_field :image %>
<% else %>
<%= image_tag(article_image.object.image.url(:thumb)) %>
<%= article_image.check_box :remove_image %> #DON'T WORK
<% end %>
<% end %>
【问题讨论】:
标签: ruby-on-rails nested-forms carrierwave nested-attributes