I’ve been trying to paginate over a list of members that all share a tag
in
common using the acts_as_taggable plugin. The regular way of paginating
over
a collection doesn’t seem to work with acts_as_taggable. Here’s what my
method looks like that takes in a tag name, finds all the members that
share
the tag and then displays all the members. Nothing too fancy at the
moment…
def show_all_tags
tag_name = params[:id] @tagged_members = Tag.find_by_name(tag_name).tagged
end
Doing the standard: @tagged_member_pages, @tagged_members = paginate
:member, :per_page => 12 displays ALL the members in the DB.
Thank you for the tips. I tried out what you suggested and it works as
expected, accpet for one glitch in it. Here’s what my code looks like
now:
def show_all_tags
if params[:id] then @tags = params[:id].split.map {|o| CGI::unescape(o)} @members = Member.find_tagged_with(@tags) @member_pages = Paginator.new(Member, @members.size, 2)
else @member_pages, @members = paginate(:member)
end
end
…and in the view:
<%= pagination_links(@member_pages) %>
<% for member in @members %>
....do stuff....
<% end %>
I’m still getting all the members showing up, even if I limit the view
to 2
members per page. The paginate links show up correctly depending on how
many
members I designate to show, but the collection of members doesn’t obey
the
pagination. I have implemented pagination to work correctly in other
areas
of my app, but using the acts_as_taggable plugin (and methods) may very
well
be the culprit here. I really have no idea!
I put the raise ‘test’ in before the paginate function, and when I run
it I
do see “test” in my browser. I also put a redirect to a general list
action
if no params come through. The “else” part of the block does work
correctly.
def show_all_tags
if params[:id] then @tag_title = params[:id] @tags = params[:id].split.map {|o| CGI::unescape(o)} @members = Member.find_tagged_with(@tags)
raise ‘test’ @members_pages = Paginator.new(Member, @members.size, 2)
else
redirect_to :action => ‘list’
end
end
paginator)
if options[:tag]==“All”
models
else
models.delete_if {|m| !m.is_tagged_with?(options[:tag])}
end
end
end
end
…but really have no idea WHERE to put it in the acts_as_taggable.rb
file.
How would you actually use something like this? Do you think this is a
viable option?
Here’s the description of it: NoteActs_as_taggeble with pagination
The following opens the pagination class back up adds the abilty to
filter
based on a single tag. Pass a :tag => “tag” and the pagination with be
base
on though s items that are tagged with it. Belongs in
acts_as_taggable.rb.
EO