我正在尝试进行一些文件版本控制,但我不能让它工作 . 我已经安装了PaperClip和PaperTrail(两者都运行得很好) . 我想要的是将一个属性 has_attached_file 添加到Version类(PaperTrail) . 到目前为止,我所做的是:

  • Initializers 文件中添加了一个文件 paper_trail

模块PaperTrail类版本<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'] end end

  • 通过PaperClip生成属性 atached_file

rails生成回形针版本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.save .

但是在我的表格版本中,图片没有保存,也没有保存在我的本地文件中 .