Comments (9)
I had this same issue but using it as a plugin.
I dug into it and found that in the lib/active_record/transitions.rb file in the "def write_state" there is the update_attributes! call. This always returned true but WOULD NOT change the state.
I made a brand-new Rails app, added the plugin, set up a model with transitions (the same transitions I was using in my failing app) and it worked just fine. I have no idea why that is but if I change the update_attributes call in that method to be this instead it works in both apps:
self.state = state.to_s
self.save!
I am unsure why this is, as update_attributes! should work just fine and returns as if it had...
from transitions.
guys, i just forked a version with an improved readme that should explain how to get this working with rails: http://github.com/jotto/transitions/blob/master/README.rdoc
i made a pull request too.
thanks for your work qoobaa
from transitions.
This may have been because you had protected the state attribute with attr_protected/attr_accessible. The update_attributes! method will not update protected attributes. I've forked and fixed here: http://github.com/tekin/transitions, pull request on the way.
from transitions.
Does it work in the current version?
from transitions.
yes, as of http://github.com/tekin/transitions/commit/c0fc41bd006ae05719dc092176fb48a0682123af.
from transitions.
Thanks.
from transitions.
Wow, tekin, that is exactly the issue... I can't believe I didn't notice that. I always seem to shoot myself in the foot with attr_accessible.
Thanks for pointing that out!
from transitions.
No worries. Deleting my fork now that changes have been pulled in.
from transitions.
I've just had a thought regarding this, update_attribute skips the callback stack (including validations) whereas update_attributes! didn't. This is obviously undesirable behaviour, although might not bite anyone right away. I'll produce another patch to make sure validations aren't skipped by transitions.
from transitions.
Related Issues (20)
- getting "uninitialized constant ActiveRecord::Transitions" with rails 4.1 HOT 2
- can_event methods don't respect guards HOT 1
- Initial state is not set HOT 3
- Problem with Success Callback HOT 5
- Refactor our specs big time
- Introduce rubocop and auto-fix offenses HOT 1
- Fix all remaining rubocop offenses in lib/ and add rubocop to our travis build HOT 1
- Transitions#set_initial_state is forcibly inserting the "state" attribute HOT 6
- new feature: put exception as a param to event_failed HOT 1
- Success callback not fired HOT 1
- Passing parameters to events HOT 1
- Raise error when guard fails HOT 6
- Throw out callbacks... HOT 5
- Introduce Reek for CI HOT 1
- Introduce RDL
- available_state available_events should list states or events in the order they are defined HOT 4
- undefined method `state_machine' for nil:NilClass HOT 4
- Multiple timestamps on state transition HOT 3
- Publish 1.3.0 release HOT 2
- Tapioca DSL compiler interest?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from transitions.