是否有人在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注意,我的comments表中有comments列。
发布于 2009-04-09 21:56:30
你需要在你的评论表中有一个名为'state‘的字段。您使用aasm_column :state定义了它。这不是Rails 2.3.2错误!:D
发布于 2009-04-09 15:39:04
从aasm主页上看,在写文章的时候,有一个更新即将到来.
在组上有一个小小的讨论--我不知道这是否有帮助。
执行
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-“、”工厂实验室-“和"runcoderun-”可能是git叉。你可能会发现一个或多个解决了你的问题。
https://stackoverflow.com/questions/734718
复制相似问题