参考
手順
versionテーブルにcommentフィールドを追加する
migrationファイル作成
$ ./bin/rails g migration add_comment_to_versions comment:text
# 20150811184014_add_comment_to_versions.rb:
class AddCommentToVersions < ActiveRecord::Migration
def change
add_column :versions, :comment, :text
end
end
migration実行
$ ./bin/rake db:migrate
モデルの修正
class Post < ActiveRecord::Base
has_paper_trail :meta => { :comment => :comment }
attr_accessor :comment
end
上記の設定後、Postモデル変更時(save
やupdate_attributes
)のパラメータにcomment
を渡すと、Versionテーブルにコメントを保存することができます。