On Nov 7, 5:40 am, C K Kashyap <[email protected]> wrote:
> Hi All,
> I have a situation where I have a task model, tag model and a link
> table task_tags.
>
> In a particular view, I need to display a list of task that have a
> certain tags -
> For this, I'd need to run a query and get the results that would need
> to be paginated - so I cannot really call
> paginate on the Task model itself.
>
> 1. What is a good way to deal with this situation?
> 2. In general, how can I use will_paginate plugin on arbitrary sql queries.
>

There's sort of an example of this in the docs:

@entries = WillPaginate::Collection.create(1, 10) do |pager|
  result = Post.find(:all, :limit => pager.per_page, :offset =>
pager.offset)
  # inject the result array into the paginated collection:
  pager.replace(result)

  unless pager.total_entries
    # the pager didn't manage to guess the total count, do it manually
    pager.total_entries = Post.count
  end
end

replace Post.find :all with a method that performs your query, using
the limit and offset passed to it and you should be fine. You may also
need to set pager.total_entries

Fred

> --
> Regards,
> Kashyap
--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to