0

有谁知道为什么这个回调方法在 Rails 2.3.x / Ruby 1.8.7 中有效,但在 Rails 3.0.x / Ruby 1.9.2 中无效?

在 Rails 2.3.x / Ruby 1.8.7 中工作:

class Post < ActiveRecord::Base
  after_create         :destroy_old_posts
  acts_as_taggable
  # ...
  protected
  def destroy_old_posts
    self.tag_list.each do |tag|
      posts = Post.find_tagged_with(tag, :order => 'updated_at DESC')
      posts[19..-1].each {|p| p.destroy } if posts.size >= 20
    end
  end
end

但是使用 3.0.x / Ruby 1.9.2 我在创建帖子时收到以下错误:

undefined method `find_tagged_with' for #<Class:0x00000002943048>

app/models/post.rb:30:in `block in destroy_old_posts'
app/models/post.rb:29:in `each'
app/models/post.rb:29:in `destroy_old_posts'
app/controllers/posts_controller.rb:29:in `block in create'
app/controllers/posts_controller.rb:28:in `create'

我正在使用acts-as-taggable-on2.0.6。感谢您阅读我的问题。

4

1 回答 1

4

我相信正确的用法是Post.tagged_with

于 2011-04-16T21:09:08.457 回答