Using will_paginate with arbitrary sql queries

View: New views
3 Messages — Rating Filter:   Alert me  

Using will_paginate with arbitrary sql queries

by C K Kashyap :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


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

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


Re: Using will_paginate with arbitrary sql queries

by Frederick Cheung-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message




On Nov 7, 5:40 am, C K Kashyap <ckkash...@...> 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 rubyonrails-talk@...
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Using will_paginate with arbitrary sql queries

by mike-609 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


You also could use paginate_by_sql

2009/11/7, C K Kashyap <ckkashyap@...>:

>
> 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
>
> >
>

--
Von meinen Mobilgerät aus gesendet

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