AASM Gem 被 Rails 2.3.2 破坏了?
有人在使用带有 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
列评论表。
- 有什么想法为什么它不再起作用吗?
Has anyone had any problems using the AASM state machine Gem with Rails 2.3.2? It was working fine for me but is now giving a 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'
Here's the relevant code from my model that uses 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
Note that I have the state
column in my comments
table.
- Any ideas why it no longer works?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
呃,您的评论表中需要一个名为“state”的字段。 您使用
aasm_column :state
定义了它。 这不是 Rails 2.3.2 的错误! :DUh, you need a field in your comments table called 'state'. You defined it using
aasm_column :state
. This is not a Rails 2.3.2 bug! :D从 aasm 主页 看来,截至撰写本文时,即将有更新...
有关于 Ruby on Rails 小组 - 我不知道这是否有帮助。
执行时
抛出了一堆引用:
它怀疑部分或全部“dvdplm-”、“factorylabs-”和“runcoderun-”可能是 git fork。 您可能会发现一个或多个可以解决您的问题。
From the aasm home page it appears that, as at time of writing, there's an update coming...
There's a little discussion on the Ruby on Rails group - I don't know if any of that helps.
Executing
threw up a bunch of references:
It suspect that some or all of the "dvdplm-", "factorylabs-" and "runcoderun-" ones may be git forks. You may find that one or more fixes your problem.