Acts_as_taggable plugin - paging through tagged model


I’m using the acts_as_taggable plugin & wanted to page through all a
model’s records taggged with a particular tags.

i.e. page through all Model records that have been tagged with “artist”

I could not work out how to do this with the plugin, so I made the
changes outlined below.

Did I need to do this…? & does anyone else find this useful?

Original - Model.find_tagged_with(“artist”)
New - Model.find_tagged_with(“artist”, { :limit => x })
New - Model.find_tagged_with(“artist”, { :limit => x, :offset => y

File: vendor/plugins/acts_as_taggable/lib/acts_as_taggable.rb

replace old find_tagged_with - with the below…

def find_tagged_with(list, options = {})
query = "SELECT #{table_name}.* FROM #{table_name}, tags, taggings "
query << "WHERE #{table_name}.#{primary_key} = taggings.taggable_id "
query << "AND taggings.taggable_type = ? "
query << "AND taggings.tag_id = AND IN (?) "
query << "limit #{options[:limit]} " if options[:limit] != nil
query << "offset #{options[:offset]} " if options[:offset] != nil
find_by_sql([query, acts_as_taggable_options[:taggable_type], list])

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs