由Rails 2.3.2破坏的AASM Gem?

时间:2009-04-09 15:26:24

标签: ruby-on-rails ruby rubygems aasm

有没有人在使用AASM状态机Gem和Rails 2.3.2时遇到任何问题?它对我来说很好,但现在给了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列。

  • 为什么它不再起作用的任何想法?

2 个答案:

答案 0 :(得分:2)

呃,你的评论表中需要一个名为'state'的字段。您使用aasm_column :state定义了它。这不是Rails 2.3.2错误! :d

答案 1 :(得分:1)

aasm home page看来,截至撰写本文时,还有更新......

Ruby on Rails group进行了一些讨论 - 我不知道是否有任何帮助。

执行

gem list .*aasm --remote

提出了一堆参考文献:

aasmith-yodlee (0.0.1.20090301132701)
bloom-aasm (2.0.3)
bloom-bloom-aasm (2.0.3)
caleb-aasm (2.0.2)
dunedain289-aasm (2.1.3)
dvdplm-aasm (2.0.6)
eric-aasm (2.0.4)
factorylabs-aasm (2.0.5.2)
gvaughn-aasm (2.0.4)
lostboy-aasm (2.0.5.1)
mikowitz-aasm (2.0.6)
netguru-aasm (2.0.6)
notch8-aasm (2.0.5)
rubyist-aasm (2.0.5)
runcoderun-aasm (2.0.5.1)
snoozer05-aasm (2.0.2)
spicycode-aasm (2.0.0)

它怀疑“dvdplm”,“factorylabs-”和“runco​​derun-”中的部分或全部可能是git forks。您可能会发现一个或多个修复了您的问题。