HighDots Forums  

Using will_paginate with arbitrary sql queries

Ruby On Rails Talk Ruby On Rails programming language mailing list


Discuss Using will_paginate with arbitrary sql queries in the Ruby On Rails Talk forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
C K Kashyap
 
Posts: n/a

Default Using will_paginate with arbitrary sql queries - 11-07-2009 , 12:40 AM






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

Reply With Quote
  #2  
Old   
Frederick Cheung
 
Posts: n/a

Default Re: Using will_paginate with arbitrary sql queries - 11-07-2009 , 05:13 AM






On Nov 7, 5:40*am, C K Kashyap <ckkash... (AT) gmail (DOT) com> wrote:
Quote:
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, ffset =>
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

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

Reply With Quote
  #3  
Old   
mike
 
Posts: n/a

Default Re: Using will_paginate with arbitrary sql queries - 11-07-2009 , 01:12 PM



You also could use paginate_by_sql

2009/11/7, C K Kashyap <ckkashyap (AT) gmail (DOT) com>:
Quote:
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 (AT) googlegroups (DOT) com
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe (AT) googlegroups (DOT) com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.