Active Admin のフォーム ブロックを使用して、現在のリソースの特定の属性がいつ更新されたかを追跡するテーブルを更新するにはどうすればよいですか?
たとえば、次のようなものがあります。
form do |f|
f.inputs "Details" do
f.input :name
f.input :address
f.input :zip
f.input :city
f.input :active_state, as: :select, collection: active_states
f.input :approval_state, as: :select, collection: approval_states
f.input :new_comment
end
f.buttons
end
以外はすべてnew_comment
、現在のリソースに存在する属性です。
リソースのクラスで次のようなことを試みました。
def new_comment
history = History.new(:id, Time.now)
history.comment
end
また、失敗したときにコントローラーのインスタンス変数を作成しようとしましたが、それも機能しませんでした。会場のクラスは、歴史のクラスとはまったく関係がありません。ユーザーが会場を編集してコメントを追加するたびに、履歴テーブルに新しい行を作成する入力列を作成しようとしています。
History モデルは次のようになります。
class History < ActiveRecord::Base
attr_accessible :comment, :venue_id, :created_at
belongs_to :venue
def initialize(id, datetime)
@id = id
@datetime = datetime
end
end
フォームは、次のような会場用です。
class Venue < ActiveRecord::Base
attr_accessible :name, :address, :zip, :city
has_many :histories
accepts_nested_attributes_for :histories
//with a bunch of methods
end
掘り下げてからこれを試してみましたが、うまくいきませんでした:
form do |f|
f.inputs "Details" do
f.input :name
f.input :address
f.input :zip
f.input :city
f.input :active_state, as: :select, collection: active_states
f.input :approval_state, as: :select, collection: approval_states
end
f.inputs "History" do
f.has_many :histories do |h|
h.input :id
h.input :comment
h.input :modified_at
end
end
f.buttons
end