4

ファイルのバージョン管理をしようとしていますが、うまくいきません。PaperClip と PaperTrail をインストールしました (どちらも問題なく動作します)。私が欲しいのは、has_attached_fileVersion クラス (PaperTrail) に属性を追加することです。これまでのところ、私がやったことは次のとおりです。

  1. paper_trail ファイルにファイルを追加しましたInitializers:

    モジュール 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']
    end

    終わり

  2. atached_filePaperClip を介して属性を生成しました

    rails generate paperclip Versions atached_file

  3. それから私がそれを使用しようとすると。私はモデルを持っていますTeamMember。だから私が欲しいのは、そのオブジェクト(特にその画像)のコピーを保存することです。

    class TeamMember < ActiveRecord::Base
    attr_accessible :name, :title, :last_name, :picture has_attached_file :picture, :styles => {:thumb => '100x100>'}

    a から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"=>"Save "}

    それで、私はこれでオブジェクトのコピーを保存しようとしました(私はいくつかのコードを省略しました):

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

    しかし、私のテーブル バージョンでは、画像は保存されておらず、ローカル ファイルにも保存されていません。

4

0 に答える 0