Hi,
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?
--------------------
Usage
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 = tags.id AND tags.name 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])
end
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---