Skip to content

Saving in after_transition on AR: Bug or bad docs? #305

Description

@danmaz74

The docs for ActiveRecord show this:

after_transition any => :parked do |vehicle, transition|
vehicle.seatbelt = 'off'
end

I would then expect that the new value for vehicle.seatbelt would be saved to the database. But this doesn't happen (state_machine v. 1.2, rails v. 3.2.15): the attribute is changed, but if I reload from the DB, it goes back to the old value.

On the contrary, the new value gets saved in a before_transition.

Is this a bug, or just something that should be clarified in the documentation?

Activity

  1. seuros commented on Mar 7, 2014

    @seuros

    vehicle.seatbelt = 'off' => vehicle.update_attribute(:seatbelt , 'off') if you using activerecord.

    The gem is for general use so it won't save the object

  2. danmaz74 commented on Mar 7, 2014

    @danmaz74
    Author

    That's ok for me, but the docs should be updated then. They're very misleading now.

  3. seuros commented on Mar 7, 2014

    @seuros

    The docs are not important for now. The whole gem is not maintained and is incompatible with new version of rails or mongodb for example.

  4. jeremywadsack commented on May 21, 2014

    @jeremywadsack

    Is this what you mean #291?

  5. cawel commented on Apr 7, 2016

    @cawel

    @seuros Stating that the "docs are not important for now" is a rather bold statement, considering the fact that this project has been starred more than 3000 times (i.e. lots of people are using this gem) and that the readme (wrongly) states that this gem supports the latest version of rails. Indeed, quoting the readme:

    ORM versions officially supported and tested:
    ActiveModel integration: 3.0.0 or later
    ActiveRecord integration: 2.0.0 or later

    I'm currently on a project using this state_machine gem and I am having issues with the after_transition callback. But only now (reading that thread – rather than the readme), I understand that the gem is not expected to work with the latest version of rails.

    Suggestion: I think the project's readme should make it clear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions