[英]File versioning with PaperTrail and PaperClip
我正在尝试进行一些文件版本控制,但我不能让它工作。 我已经安装了PaperClip和PaperTrail(两者都运行得很好)。 我想要的是将一个属性has_attached_file
添加到Version类(PaperTrail)。 到目前为止,我所做的是:
在Initializers
文件中添加了一个文件paper_trail
:
模块PaperTrail
class Version <ActiveRecord :: Base
attr_accessible:parent_id,:admin_edit
has_attached_file:atached_file
validates_attachment_content_type:atached_file,:content_type => ['image / jpeg','application / pdf']
结束结束
生成的属性atached_file
通过回形针
rails generate paperclip Versions atached_file
然后,当我尝试使用它。 我有一个模型TeamMember
。 所以我想要的是保存该对象的副本(特别是该图像)。
class TeamMember <ActiveRecord :: Base
attr_accessible:name,:title,:last_name,:picture has_attached_file:picture,:styles => {:thumb =>'100x100>'}
从Form
我得到以下参数:
参数:{“utf8”=>“✓”,“authenticity_token”=>“345345345 =”,“team_member”=> {“name”=>“aaa”,“last_name”=>“vv”,“title”= >“ddd”,“picture”=>#ActionDispatch :: Http :: UploadedFile:0x007f39f173bc98 @ original_filename =“rails.png”,@ content_type =“image / png”,@ headers =“Content-Disposition:form-data; name = \\“team_member [picture] \\”; filename = \\“rails.png \\”\\ r \\ nContent-Type:image / png \\ r \\ n“,@ tempfile =#>},”commit“=>”保存“}
所以,我试图用这个保存对象的副本(我省略了一些代码):
version.atached_file = params[:picture]
version.saveversion.atached_file = params[:picture]
。
version.save
但是在我的表格版本中,图片没有保存,也没有保存在我的本地文件中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.