有没有人在使用带有 Rails 2.3.2的AASM状态机 Gem 时遇到任何问题?它对我来说工作正常,但现在给出NoMethodError
:
NoMethodError (undefined method `state' for #<Comment:0x25cb8ac>):
/usr/local/lib/ruby/gems/1.8/gems/rubyist-aasm-2.0.5/lib/persistence/active_record_persistence.rb:231:in `send'
/usr/local/lib/ruby/gems/1.8/gems/rubyist-aasm-2.0.5/lib/persistence/active_record_persistence.rb:231:in `aasm_read_state'
/usr/local/lib/ruby/gems/1.8/gems/rubyist-aasm-2.0.5/lib/persistence/active_record_persistence.rb:135:in `aasm_current_state'
/usr/local/lib/ruby/gems/1.8/gems/rubyist-aasm-2.0.5/lib/persistence/active_record_persistence.rb:156:in `aasm_ensure_initial_state'
app/controllers/comments_controller.rb:12:in `create'
这是我的模型中使用 AASM 的相关代码:
class Comment < ActiveRecord::Base
include AASM
belongs_to :post
after_create :spam_check
aasm_column :state
aasm_initial_state :submitted
aasm_state :submitted
aasm_state :approved
aasm_state :rejected
aasm_event :ham do
transitions :to => :approved, :from => [:submitted, :rejected]
end
aasm_event :spam do
transitions :to => :rejected, :from => [:submitted, :approved]
end
private
def spam_check
# Invoke Askismet to see if the comment is spam...
end
end
请注意,我的表state
中有该列comments
。
- 任何想法为什么它不再起作用?