Hi all, In my controller def index @customers = Customer.find(:all) @size = @customers.size @total_pages = (@customers.size / $PER_PAGE.to_f).ceil end In index.html.erb Displays a customer list with pagination(Example: 1,2,3,4,5....) On each page number click (Example: 1,2,3,4,5...) - the below code in index function gets executed. @customers = Customer.find(:all) @size = @customers.size @total_pages = (@customers.size / $PER_PAGE.to_f).ceil This results in performace lack. So I want to read the db records only once and store it in some variable. And i will use that variable to display the records for 2,3,4,5 pages. Please note: I don''t want to use any plugins and please help to implement.. -- Posted via http://www.ruby-forum.com/.
hey dude. I think by your requirement, you''d better use the ajax for the pagination. read all the records from DB in your index action, and latter use ajax for the pagination(you will not need access your index action again ) BTW: will you use cache in your app? if, yes your way is not bad either. Though every time when you selecting the page, you will access the index action. but it will not get the records from your DB , it will get from your cache. I prefer the cache one. Hope it gives you some help. yours, Terry 2009/9/9 Venkat Eee <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>:> > Hi all, > > In my controller > def index > @customers = Customer.find(:all) > @size = @customers.size > @total_pages = (@customers.size / $PER_PAGE.to_f).ceil > end > > In index.html.erb > Displays a customer list with pagination(Example: 1,2,3,4,5....) > > On each page number click (Example: 1,2,3,4,5...) - the below code in > index function gets executed. > > @customers = Customer.find(:all) > @size = @customers.size > @total_pages = (@customers.size / $PER_PAGE.to_f).ceil > > This results in performace lack. > > So I want to read the db records only once and store it in some > variable. > And i will use that variable to display the records for 2,3,4,5 pages. > > Please note: I don''t want to use any plugins and please help to > implement.. > -- > Posted via http://www.ruby-forum.com/. > > > >
will_paginate plugin is best solution It can retrieve records for particular page, not whole record set. @customers = Customer.paginate( :page => :params[:page], :limit => 10 ) Sandip R~ On Wed, Sep 9, 2009 at 11:56 AM, Terry <poshboytl-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > hey dude. > I think by your requirement, you''d better use the ajax for the pagination. > read all the records from DB in your index action, and latter use ajax > for the pagination(you will not need access your index action again ) > > BTW: will you use cache in your app? if, yes your way is not bad > either. Though every time when you selecting the page, you will access > the index action. but it will not get the records from your DB , it > will get from your cache. > > I prefer the cache one. > > Hope it gives you some help. > > yours, > Terry > > > 2009/9/9 Venkat Eee <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>: > > > > Hi all, > > > > In my controller > > def index > > @customers = Customer.find(:all) > > @size = @customers.size > > @total_pages = (@customers.size / $PER_PAGE.to_f).ceil > > end > > > > In index.html.erb > > Displays a customer list with pagination(Example: 1,2,3,4,5....) > > > > On each page number click (Example: 1,2,3,4,5...) - the below code in > > index function gets executed. > > > > @customers = Customer.find(:all) > > @size = @customers.size > > @total_pages = (@customers.size / $PER_PAGE.to_f).ceil > > > > This results in performace lack. > > > > So I want to read the db records only once and store it in some > > variable. > > And i will use that variable to display the records for 2,3,4,5 pages. > > > > Please note: I don''t want to use any plugins and please help to > > implement.. > > -- > > Posted via http://www.ruby-forum.com/. > > > > > > > > > > >-- Ruby on Rails Developer http://sandip.sosblog.com http://funonrails.wordpress.com www.joshsoftware.com --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks, @Sandip Ransing @Terry Terry I have a doubt.... If i write a function in application_helper.rb( Example: set and get variable functions). It''s possible to implement my requirement...? -- Posted via http://www.ruby-forum.com/.
no... it will not... the problem is, there is no place for you to save the records.... because the http protocol is no state. every time when you refresh the page, the variable is gone... yours, Terry 2009/9/9 Venkat Eee <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>:> > Thanks, @Sandip Ransing @Terry Terry > > I have a doubt.... > > If i write a function in application_helper.rb( Example: set and get > variable functions). > > It''s possible to implement my requirement...? > > > -- > Posted via http://www.ruby-forum.com/. > > > >
On Sep 9, 2:06 am, Venkat Eee <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Please note: I don''t want to use any plugins and please help to > implement..You don''t want to use any plugins? Then you either need to get a new job or stop asking rails-talk to do your homework... Seriously though, mislav-will_paginate on github does exactly what you''re looking for. Don''t re-invent the wheel. --Matt Jones