Rails 3 Carrierwave 如何删除模型属性文件?
我关注了 Railcast #253 http://railscasts.com/episodes/253-rierwave-file -上传并且效果很好。但后来我用 ActiveAdmin 和 Formtastic 实现了它(ActiveAdmin 使用 Formtastic 作为表单)。
所以我可以上传文件和下载文件。
问题是,当链接到删除链接时,Carrierwave 似乎需要一个模型而不是模型的属性。
我有模型 Shipment,它具有 hbl_pdf 属性(PDF 文档)。这是我的删除链接...
row("HBL") { link_to 'remove', shipment.hbl_pdf, :confirm => "Are you sure?", :method => :delete }
我收到错误... PdfUploader:Class 的未定义方法 model_name
我不想删除货件,只想删除文档。
I followed the Railcast #253 http://railscasts.com/episodes/253-carrierwave-file-uploads and works great. But then I implemented it with ActiveAdmin and therefore Formtastic (ActiveAdmin uses Formtastic for the forms).
So I'm able to upload files and download files.
Problem is, it seems that Carrierwave expects a model instead of an attribute of the model when linking to remove links.
I have model Shipment, which has hbl_pdf attribute (a PDF document). This is my delete link...
row("HBL") { link_to 'remove', shipment.hbl_pdf, :confirm => "Are you sure?", :method => :delete }
I get error... undefined method model_name for PdfUploader:Class
I don't want to delete the shipment, only the document.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么不对货件对象调用
remove_hbl_pdf!
呢?阅读以下内容的“删除上传的文件”部分:https://github.com/jnicklas/rierwave#readme< /a>并在您的控制器中
删除命令的语法基于您的属性名称。因此,如果您的模型属性名称是
.hbl_pdf
那么它就是remove_hbl_pdf!
,如果它是.image
那么它就是remove_image!
Why aren't you calling
remove_hbl_pdf!
on the shipment object instead? Read the "Removing uploaded files" section of this: https://github.com/jnicklas/carrierwave#readmeand in your controller
The syntax for the remove command is based on the name of your attribute. So if your model attribute name is
.hbl_pdf
then it isremove_hbl_pdf!
and if it was.image
then it would beremove_image!