Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Adding of a state in AASM consists of creating a new State object, which is then added to AASM::StateMachine[User].states array, which looks like this:</p> <pre><code>def create_state(name, options) @states &lt;&lt; AASM::SupportingClasses::State.new(name, options) unless @states.include?(name) end </code></pre> <p>The thing to notice here is that it won't allow to override a state once it is set. If the state with the same name is set again, create_state method just ignores it. To slove this problem, you can use something like this in your User model:</p> <pre><code># this will remove the state with name :name from the states array states = AASM::StateMachine[self].states states.delete(states.find{ |s| s == :name }) # ... so we can define the state here again aasm_state :name ... </code></pre> <p>If you are just redefining the state you should be fine now. But if you want to remove the state entirely, you should undefine the method defined in the body of aasm_state method, too. It should be possible with calling something like:</p> <pre><code>undef_method :name </code></pre> <p>The situation should be the same with events (just use "events" instead of "states" in the code). Ideally, make it User model's class method that overrides methods defined in AASM module. In the case of states it would look like this:</p> <pre><code>def aasm_state(name, options={}) states = AASM::StateMachine[self].states states.delete(states.find{ |s| s == name.to_sym }) super(name, options) end </code></pre> <p>Warning: I might not be right. This code is untested, I just figured it out by looking into the source code of AASM.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload