Ruby on Rails 3.2.2を使用していますが、プロセスフロー中に属性値が設定されているかどうかを確認する方法があるかどうかを知りたいです。つまり、属性、、、を持つクラスがArticle
あります。title
content
updater_user_id
私のコントローラーには次のものがあります。
# @article.title
# => "Sample title"
# @article.content
# => "Sample content"
# @article.updater_user_id
# => 1
# @current_user.id
# => 1 # Note: This value is the same as '@article.updater_user_id'
@article.updater_user_id = @current_user.id
# params[:article]
# => {:article => {:title => 'Sample title 2', :content => 'Sample content 2'}}
@article.update_attributes(params[:article])
この方法を使用しようとしました@article.changed
が、動作させたいので動作しません。実際、そのメソッドは次を返します。
@article.changed
# => ['title', 'content'] # Note: There isn't the 'updater_user_id' attribute
updater_user_id
つまり、値が変更されていなくても、プロセスフロー中にが設定されているかどうかを確認したいと思います。私のユースケースは、オブジェクトを保存する前に、プロセスフロー中にを(少なくとも1回)設定することを要求したいというものです。プロセスフロー中に設定されていない場合は、エラーなどを発生させたいと思います。updater_user_id
Article
出来ますか?もしそうなら、それを作る方法は?