-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
write_state_without_persistence confusion #16
Comments
Totally agree! I'm using mongoid. Consider something like: before_save :expire_free_trial
def expire_free_trial
begin
trial_expired if Time.now - created_at > FREE_TRIAL_PERIOD
self.state = self.current_state
rescue Transitions::InvalidTransition
end
end It took me quite a while to figure out that line that sets the state attribute. I'd expect that to be set when the non-bang event fires. Perhaps that works only for active record? |
@robolson, @venetanji could you submit a pull request which updates our documentation? |
As someone who stumbled on the project and tried to use it with ActiveRecord, this issue caused me a lot of confusion. I expected the behavior of calling an event like |
Closed thanks to @zmillman |
While attempting to use this gem I kept running into the issue where the persistence method with a bang(!) was not working.
In the README it talks about how "both events will call write_state_without_persistence on successful transition". What it does not say is that write_state_without_persistence is not defined for you in Rails or in the transitions gem. Which leaves the gem author to implement this method if the non bang-version is going to do anything other than set the @default_current_state instance variable.
I added the following to my ActiveRecord user class:
which does the trick, but it also means
self.state=
is called once insidewrite_state
and again insidewrite_state_without_persistence
.I feel like I am missing something here. What is the proper way to use this gem with the non bang(!)-versions of the events?
The text was updated successfully, but these errors were encountered: