0
我有在這裏的屬性 跟蹤變化的問題是我的模型跟蹤更改
class Ticket < ActiveRecord::Base
include Generator
around_update :create_history
def create_history
@event_status = "Status to #{self.status}.\n" if status_changed?
@event_owner = "Now it is provided by #{self.stuff.name}\n" if stuff_id_changed?
yield
histories.create(event: "Changed! #{@event_status} #{@event_owner} On #{self.updated_at.utc}") if @event_status || @event_owner
end
end
行動更新是微不足道
def update
flash[:notice] = "Your ticket successfully updated."
@ticket.update!(ticket_params.merge(status: 0))
end
但是,這並不工作,在創造歷史(規格我會和這個小時戰鬥,如果有任何反應指出我的錯誤,我會很感激的
you user'ticket_params.merge(status:0)'所以你的'status'總是'0'。它不會改變 – Aleksey
也我會推薦使用[paper_trail](https://github.com/airblade/paper_trail)寶石。它具有非常好的功能來版本化你的模型。 – Aleksey
和'stuff_id'值呢?莫名其妙地改變了嗎? – Aleksey