class CreateBooks < ActiveRecord::Migration
def change
create_table :books do |t|
t.integer :state, :default => 1
t.timestamps
end
end
end
model
class Book < ActiveRecord::Base
state_machine :state do
state :foo, :value => 1
end
end
rails console
% rails console
> Book
> reload!
> Book
Both Book and its :state machine have defined a different default for "state". Use only one or the other for defining defaults to avoid unexpected behaviors.
How to reproduce
migration
model
rails console
I think
StateMachine::Machine#initial_state
method should ignorenil
arg. https://github.com/pluginaweek/state_machine/blob/master/lib/state_machine/machine.rb#L629Thanks