I am using Ruby on Rails 3.2.2 and I would like to know if there is a way to check if an attribute value has been set during the process flow. That is, I have an Article class with attributes title, content, updater_user_id.
In my controller I have:
# @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])
I tried to use the @article.changed method but it doesn’t work as I would like it to work. In fact, that method returns:
@article.changed
# => ['title', 'content'] # Note: There isn't the 'updater_user_id' attribute
In other words, I would like to check if the updater_user_id has been set during the process flow even if that value has not changed. My use case is that I would like to require that the updater_user_id is set (at least one time) during the process flow before to save an Article object; if it is not set during the process flow, then I would like to raise an error or something like that.
Is it possible? If so, how to make that?
Did you try
xxx_will_change!method?