Nathan Long
Nathan Long

Reputation: 126112

With the state_machine gem, can I can I perform a transition without saving?

I'm working on an app that uses state_machine. I want to call a transition method but not persist the change, so that I have an opportunity to check whether the proposed change is authorized. Eg:

def some_controller_action
  # ...
  account.close     # but don't save...
  authorize account # will explode if current_user may not do this
  if account.save ....

How can I do this?

Upvotes: 1

Views: 32

Answers (1)

Nathan Long
Nathan Long

Reputation: 126112

Pass false

Eg:

account.close(false) # does not save

This isn't exactly documented, but I found it here.

Upvotes: 1

Related Questions