ファイルのバージョン管理をしようとしていますが、うまくいきません。PaperClip と PaperTrail をインストールしました (どちらも問題なく動作します)。私が欲しいのは、has_attached_file
Version クラス (PaperTrail) に属性を追加することです。これまでのところ、私がやったことは次のとおりです。
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終わり
atached_file
PaperClip を介して属性を生成しました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>'}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しかし、私のテーブル バージョンでは、画像は保存されておらず、ローカル ファイルにも保存されていません。