4

我正在尝试进行一些文件版本控制,但我无法使其工作。我已经安装了 PaperClip 和 PaperTrail(两者都工作得很好)。我想要的是has_attached_file向版本类(PaperTrail)添加一个属性。到目前为止,我所做的是:

  1. paper_trail 在文件中添加了一个Initializers文件:

    模块 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

    结尾

  2. atached_file通过 PaperClip生成属性

    rails generate paperclip Versions atached_file

  3. 然后当我尝试使用它时。我有一个模型TeamMember。所以我想要的是保存该对象的副本(特别是该图像)。

    类 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[图片]\"; filename=\"rails.png\"\r\nContent-Type: image/png\r\n", @tempfile=#>}, "commit"=>"保存"}

    所以,我试图用这个来保存对象的副本(我省略了一些代码):

    version.atached_file = params[:picture]
    version.save
    .

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

4

0 回答 0