截至目前,用户可以将图片上传到活动管理员,还可以查看此图片的预览。但是,我不确定如何为此图像添加删除按钮。这是我的代码,现在在Active Admin中用于内容的输入视图:
ActiveAdmin.register Content do
form :html => { :enctype => "multipart/form-data" } do |f|
f.input :image, :as => :file, :hint => f.template.image_tag(f.object.image.url(:thumb))
f.input :remove_image, as: :boolean, required: false, label: "remove image"
end
f.buttons
end
Model Content.rb
attr_writer :remove_image
def remove_image
@remove_image || false
end
def before_remove_image
if self.remove_image
self.remove_image = nil
end
end
当我检查布尔值并尝试更新它时,它会抛出以下错误:
RSolr::Error::Http - 500 Internal Server Error
Error: /Users/LMo/Made/gluten-free-all/gluten-free/solr/data/development/index/segments_11 (No such file or directory)
java.io.FileNotFoundException: /Users/LMo/Made/gluten-free-all/gluten-free/solr/data/development/index/segments_11 (No such file or directory)
at java.io.RandomAccessFile.open(Native Method)
at java.io.RandomAccessFile.<init>(RandomAccessFile.java:233)
at org.apache.lucene.store.SimpleFSDirectory$SimpleFSIndexInput$Descriptor.<init>(SimpleFSDirectory.java:70)
at org.apache.lucene.store.SimpleFSDirectory$SimpleFSIndexInput.<init>(SimpleFSDirectory.java:97)
at org.apache.lucene.store.NIOFSDirectory$NIOFSIndexInput.<init>(NIOFSDirectory.java:92)
at org.apache.lucene.store.NIOFSDirectory.openInput(NIOFSDirectory.java:79)
at org.apache.lucene.store.FSDirectory.openInput(FSDirectory.java:345)
at org.apache.lucene.index.SegmentInfos.read(SegmentInfos.java:265)
答案 0 :(得分:3)
我用过这个,但它可能适用于旧版本的ActiveAdmin。也许你可以修改它吗?
# In app/admin/model.rb
form :html => { :enctype => "multipart/form-data" } do |f|
f.inputs do
#...
f.input :icon, :as => :file, :label => "Icon", :hint => f.template.(f.object.icon.url(:thumb))
if (f.object.icon.present?)
f.input :delete_icon, :as=> :boolean, :required => false, :label => 'Remove image'
end
end
f.buttons
end
# model.rb
attr_accessor :delete_icon
before_validation { self.icon.clear if self.delete_icon == '1' }
答案 1 :(得分:0)
谢谢你的帮助。这是最终的工作代码......
系统管理员/ product.rb 强>
f.input :image, required: false, hint: (("Current image:<br/>").html_safe + f.template.image_tag(f.object.image.url(:thumb))).html_safe
f.input :remove_image, as: :boolean, required: false, label: "Remove Image"
<强>模型/ product.rb 强>
attr_writer :remove_image
def remove_image
@remove_image || false
end
before_validation { self.image.clear if self.remove_image == '1' }