Coder Social home page Coder Social logo

Comments (9)

JohnPostlethwait avatar JohnPostlethwait commented on July 20, 2024

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.

jotto avatar jotto commented on July 20, 2024

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.

tekin avatar tekin commented on July 20, 2024

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.

qoobaa avatar qoobaa commented on July 20, 2024

Does it work in the current version?

from transitions.

tekin avatar tekin commented on July 20, 2024

yes, as of http://github.com/tekin/transitions/commit/c0fc41bd006ae05719dc092176fb48a0682123af.

from transitions.

qoobaa avatar qoobaa commented on July 20, 2024

Thanks.

from transitions.

JohnPostlethwait avatar JohnPostlethwait commented on July 20, 2024

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.

tekin avatar tekin commented on July 20, 2024

No worries. Deleting my fork now that changes have been pulled in.

from transitions.

tekin avatar tekin commented on July 20, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.