AASM4.1.1 не может работать на Rails4

У меня есть модель, которая содержит поле с именем "status". Я изменил его на тип String в DB. И я также использую enum в AASM.
вот мой код:

class Card < ActiveRecord::Base
  include AASM

  enum status: {
    default: 0,
    published: 1,
    deleted: 2
  }

  aasm column: :status, enum: true, skip_validation_on_save: true, no_direct_assignment: true do
    state :default, initial: true
    state :published
    state :deleted

    event :publish do
      transitions from: :default, to: :published
    end

    event :delete do
      transitions from: :published, to: :deleted
    end
  end
end

И я применяю это так:

Card card = Card.first
card.publish

Неважно, я звоню card.publish или же card.deleteЯ получу ошибку, как это:

NoMethodError: undefined method `name' for nil:NilClass
    from /Users/MadisonRong/.rvm/gems/ruby-2.0.0-p598/gems/aasm-4.1.1/lib/aasm/core/state.rb:15:in `=='
    from /Users/MadisonRong/.rvm/gems/ruby-2.0.0-p598/gems/aasm-4.1.1/lib/aasm/instance_base.rb:61:in `block in state_object_for_name'
    from /Users/MadisonRong/.rvm/gems/ruby-2.0.0-p598/gems/aasm-4.1.1/lib/aasm/instance_base.rb:61:in `each'
    from /Users/MadisonRong/.rvm/gems/ruby-2.0.0-p598/gems/aasm-4.1.1/lib/aasm/instance_base.rb:61:in `find'
    from /Users/MadisonRong/.rvm/gems/ruby-2.0.0-p598/gems/aasm-4.1.1/lib/aasm/instance_base.rb:61:in `state_object_for_name'
    from /Users/MadisonRong/.rvm/gems/ruby-2.0.0-p598/gems/aasm-4.1.1/lib/aasm/aasm.rb:62:in `aasm_fire_event'
    from /Users/MadisonRong/.rvm/gems/ruby-2.0.0-p598/gems/aasm-4.1.1/lib/aasm/persistence/active_record_persistence.rb:175:in `block in aasm_fire_event'
    from /Users/MadisonRong/.rvm/gems/ruby-2.0.0-p598/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
    from /Users/MadisonRong/.rvm/gems/ruby-2.0.0-p598/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/transaction.rb:188:in `within_new_transaction'
    from /Users/MadisonRong/.rvm/gems/ruby-2.0.0-p598/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
    from /Users/MadisonRong/.rvm/gems/ruby-2.0.0-p598/gems/activerecord-4.2.0/lib/active_record/transactions.rb:220:in `transaction'
    from /Users/MadisonRong/.rvm/gems/ruby-2.0.0-p598/gems/aasm-4.1.1/lib/aasm/persistence/active_record_persistence.rb:175:in `aasm_fire_event'
    from /Users/MadisonRong/.rvm/gems/ruby-2.0.0-p598/gems/aasm-4.1.1/lib/aasm/base.rb:81:in `block in event'
    from (irb):13
    from /Users/MadisonRong/.rvm/gems/ruby-2.0.0-p598/gems/railties-4.2.0/lib/rails/commands/console.rb:110:in `start'
    from /Users/MadisonRong/.rvm/gems/ruby-2.0.0-p598/gems/railties-4.2.0/lib/rails/commands/console.rb:9:in `start'
    from /Users/MadisonRong/.rvm/gems/ruby-2.0.0-p598/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:68:in `console'
    from /Users/MadisonRong/.rvm/gems/ruby-2.0.0-p598/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
    from /Users/MadisonRong/.rvm/gems/ruby-2.0.0-p598/gems/railties-4.2.0/lib/rails/commands.rb:17:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'2.0.0-p598 :014 >

Это озадачивает меня на несколько дней. Любая помощь будет признательна.

1 ответ

Не должно ли это быть

enum status: [
  :default,
  :published,
  :deleted
]

? Если это не поможет, пожалуйста, откройте вопрос на GitHub, и я более подробно на него посмотрю.

Другие вопросы по тегам