On Monday, May 28, 2012 9:42:54 PM UTC-4, Gurpartap Singh wrote:
> Shouldn't the transition callbacks only run after validation, before and
> after save?
> On Monday, May 28, 2012 8:56:43 PM UTC+5:30, Aaron Pfeifer wrote:
>> Hey Gurpartap -
>> before_transition callbacks are run prior to validations.
>> after_transition callbacks are run after the record saves successfully.
>> There really aren't any transition callbacks that run after validations
>> but prior to saving.
>> Hope this helps clarify things!
>> -Aaron
>> On Saturday, May 26, 2012 2:56:32 PM UTC-4, Gurpartap Singh wrote:
>>> Even when the following general validation[1] fails, the changed
>>> state_event param passed from the form triggers it's transition callbacks
>>> to be fired.
>>> validate :validate_name_change, :on => :update
>>> def validate_name_change
>>> if name.to_s != name_was.to_s
>>> errors.add(:name, "can't be changed")
>>> return false
>>> end
>>> end
>>> [1] not inside the state_machine block.
>>> What's the way out? Sorry I have been asking a lot here lately, but I
>>> guess my questions and their subsequent answers would help others in doubt.