То, как обнаружить атрибут, изменяется из модели?

Одно быстрое дополнительное, которое я не видел, но что я делаю часто: скопируйте таблицу Ваш, обновляют. Я делаю это при наличии базы данных для содержания этих резервных копий. Я могу тогда записать:

select *
  into MyBackupDb..PeterTableName2008_09_28BeforeABigUpdate

Это делает восстановление после ошибок намного быстрее в будущем (когда полное восстановление не практично).

84
задан David C 19 October 2009 в 01:10
поделиться

2 ответа

You should look at ActiveModel::Dirty module: You should be able to perform following actions on your Claim model:

claim.status_changed?  # returns true if 'status' attribute has changed
claim.status_was       # returns the previous value of 'status' attribute
claim.status_change    # => ['old value', 'new value'] returns the old and 
                       # new value for 'status' attribute

claim.name = 'Bob'
claim.changed # => ["name"]
claim.changes # => {"name" => ["Bill", "Bob"]}

Oh! the joys of Rails!

170
ответ дан 24 November 2019 в 08:28
поделиться

I recommend you have a look at one of the available state machine plugins:

Either one will let you setup states and transitions between states. Very useful and easy way of handling your requirements.

3
ответ дан 24 November 2019 в 08:28
поделиться
Другие вопросы по тегам:

Похожие вопросы: