You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :status
end
end
end
Model:
class User < ActiveRecord::Base
include ActiveModel::Transitions
state_machine :attribute_name => :status, :initial => :new do
state :registered
end
end
Console:
➜ app1 rails c
Loading development environment (Rails 4.0.1)
irb(main):001:0> u = User.new
NoMethodError: undefined method `call_action' for nil:NilClass
from /Users/valentin/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/transitions-0.1.11/lib/active_model/transitions.rb:93:in `set_initial_state'
from /Users/valentin/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/activesupport-4.0.1/lib/active_support/callbacks.rb:375:in `_run__1719794837482552169__initialize__callbacks'
from /Users/valentin/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/activesupport-4.0.1/lib/active_support/callbacks.rb:80:in `run_callbacks'
from /Users/valentin/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/activerecord-4.0.1/lib/active_record/core.rb:188:in `initialize'
from /Users/valentin/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/activerecord-4.0.1/lib/active_record/inheritance.rb:27:in `new'
from /Users/valentin/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/activerecord-4.0.1/lib/active_record/inheritance.rb:27:in `new'
from (irb):1
from /Users/valentin/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/railties-4.0.1/lib/rails/commands/console.rb:90:in `start'
from /Users/valentin/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/railties-4.0.1/lib/rails/commands/console.rb:9:in `start'
from /Users/valentin/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/railties-4.0.1/lib/rails/commands.rb:62:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
Error goes away when I set the initial state implicitly in a block.
The text was updated successfully, but these errors were encountered:
@Valve I investigated this issue and this is NOT a rails 4 problem. The problem is that you your initial state name is not listed as state at all, hence the error.
Coming from this issue: #108
Another way to repro this issue:
Gemfile:
Migration:
Model:
Console:
Error goes away when I set the initial state implicitly in a block.
The text was updated successfully, but these errors were encountered: