Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Transition callback fired in spite of failed general validation
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Gurpartap Singh  
View profile  
 More options May 26 2012, 2:56 pm
From: Gurpartap Singh <gurpar...@gmail.com>
Date: Sat, 26 May 2012 11:56:32 -0700 (PDT)
Local: Sat, May 26 2012 2:56 pm
Subject: Transition callback fired in spite of failed general validation

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.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Aaron Pfeifer  
View profile  
 More options May 28 2012, 11:26 am
From: Aaron Pfeifer <aaron.pfei...@gmail.com>
Date: Mon, 28 May 2012 08:26:43 -0700 (PDT)
Local: Mon, May 28 2012 11:26 am
Subject: Re: Transition callback fired in spite of failed general validation

Hey Gurpartap -

before_transition callbacks are run prior to validations.  after_transitioncallbacks 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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Gurpartap Singh  
View profile  
 More options May 28 2012, 9:42 pm
From: Gurpartap Singh <gurpar...@gmail.com>
Date: Mon, 28 May 2012 18:42:54 -0700 (PDT)
Local: Mon, May 28 2012 9:42 pm
Subject: Re: Transition callback fired in spite of failed general validation

Shouldn't the transition callbacks only run after validation, before and
after save?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Aaron Pfeifer  
View profile  
 More options May 28 2012, 10:46 pm
From: Aaron Pfeifer <aaron.pfei...@gmail.com>
Date: Mon, 28 May 2012 19:46:44 -0700 (PDT)
Local: Mon, May 28 2012 10:46 pm
Subject: Re: Transition callback fired in spite of failed general validation

Validations need to run within the context of the state of a record.  In
order for that to happen, the transition needs to start prior to
validations getting run.  As a result, transition callbacks run prior to
validations.

You can always customize this behavior using something like below, but I
wouldn't recommend it.. (note that I haven't tested an implementation like
this)

class Vehicle < ActiveRecord::Base
  ...
  state_machine :action => nil do
    before_transition {|vehicle, transition| ...}
    before_transition :save
    ...
  end
end

-Aaron


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »