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 に答える