Callback with Acts-As-Taggable-On: Undefined method in Rails 3, works beautifully in Rails 2.3
Does anyone know why this callback method would work in Rails 2.3.x / Ruby 1.8.7 but not in Rails 3.0.x / Ruby 1.9.2?
Works in 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
But with 3.0.x / Ruby 1.9.2 I receive the following error upon creating a post:
undefined method `find_tagged_with' for #<Class:0x00000002943048>
app/models/post.rb:30:in `block in des开发者_如何学编程troy_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'
I'm using acts-as-taggable-on
2.0.6. Thank you for reading my question.
I believe the correct usage is Post.tagged_with
精彩评论