开发者

Callback with Acts-As-Taggable-On: Undefined method in Rails 3, works beautifully in Rails 2.3

开发者 https://www.devze.com 2023-02-26 07:10 出处:网络
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?

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号