state_machine: Initial state doesn't work in Rails 4.2

Hi, I have problem with initial state in new Rails 4.2

class User < ActiveRecord::Base
  state_machine initial: :waiting_confirmation do
    state :waiting_confirmation
    state :active
  end
end
Loading development environment (Rails 4.2.0)
[1] pry(main)> User.new.state
=> nil

Any ideas?

About this issue

  • Original URL
  • State: open
  • Created 10 years ago
  • Comments: 26

Most upvoted comments

I use https://github.com/seuros/state_machine with Rails 4.2

everything work now

Guys, just use state_machines-activerecord.

I got the same problem too, i’m using this (for now) (in your model where :draft is initial)

    after_initialize :set_initial_status
    def set_initial_status
      self.status ||= :draft
    end