Using will_paginate with arbitrary sql queries

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.


Regards,
Kashyap

On Nov 7, 5:40 am, C K Kashyap [email protected] wrote:

  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

You also could use paginate_by_sql

2009/11/7, C K Kashyap [email protected]:

  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.


Regards,
Kashyap


Von meinen Mobilgerät aus gesendet