Skip to content
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

assigning state_event overrides the state no matter what in Rails 4.2 #22

Closed
jcohenho opened this issue May 19, 2015 · 1 comment
Closed

Comments

@jcohenho
Copy link

This might be a related issue: pluginaweek/state_machine#327
Here I have a Car class:

class Car < ActiveRecord::Base
  attr_accessible :state_event

  state_machine :state, initial: :parked do
    event :drive do
      transition :parked => :driving
    end
    event :stop do
      transition :driving => :parked
    end
    event :turn_right do
      transition :driving => :moving_right 
    end
  end

end
c = Car.create!
c.update_attributes({ state_event: :turn_right })

The last command will successfully save the car and update the state attribute to :turn_right, even though it should fail and return false, since a car cannot move from it's initial :parked state to :moving_right.
If I run:

c.state = :moving_right
c.save!

I will get the false value properly returned.

@jcohenho
Copy link
Author

closed because Rails 4 upgrade fail. I had to add attr_accessible to :state_event.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant