I am using Ruby on Rails 3.2.9 and I am just trying to use the state_machine stone. I have the following statements:
# Model class attributes are: # # [String] status # [Boolean] checkin_1 # [Boolean] checkin_2 # class Article < ActiveRecord::Base state_machine :attribute => :status, :initial => :unconfirmed do state :confirmed, :value => 'confirmed' state :unconfirmed, :value => 'unconfirmed' event :confirm do transition :unconfirmed => :confirmed end event :unconfirm do transition :confirmed => :unconfirmed end end end
I would like to add custom check messages for instance objects (avoiding saving these objects) when the confirm and checkin_1 and / or checkin_2 are false . That is, given that I'm trying to execute confirm each of the following objects:
<#Article id: 1, :status: 'unconfirmed', checkin_1: false, checkin_2: false> <#Article id: 1, :status: 'unconfirmed', checkin_1: false, checkin_2: true> <#Article id: 1, :status: 'unconfirmed', checkin_1: true, checkin_2: false>
then I would like to avoid saving objects and add accordingly error messages like the following:
"can not be confirmed if it is not checked for 1 and 2" "can not be confirmed if it is not checked for 1" "can not be confirmed if it is not checked for 2"
How can I do it?
source share