Mathieu Chappuis
2005-Dec-29 09:07 UTC
Paginate do a Count(*) request before, how access that count value.
Hello, AV::paginate query first by a count, how access this value in the controller or view ? Why ? Because I''ll like to display the total number or records found w/o doing another expenssive Count. Thanks,
Thibaut Barrère
2005-Dec-29 10:04 UTC
Re: Paginate do a Count(*) request before, how access that count value.
Hi Mathieu maybe you could use a cached counter value in the database, as shown in the rails-blog-in-15-minutes-video ? (a bit different from what you exactly describe, but less expensive as well) hope this helps Thibaut On 29/12/05, Mathieu Chappuis <mathieu.chappuis.lists-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hello, > > AV::paginate query first by a count, how access this value in the > controller or view ? > > Why ? > > Because I''ll like to display the total number or records found w/o > doing another expenssive Count. > > Thanks, > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Thibaut Barrère
2005-Dec-29 10:05 UTC
Re: Paginate do a Count(*) request before, how access that count value.
Unless of course you need to query with conditions :) On 29/12/05, Thibaut Barrère <thibaut.barrere-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi Mathieu > > maybe you could use a cached counter value in the database, as shown in > the rails-blog-in-15-minutes-video ? (a bit different from what you exactly > describe, but less expensive as well) > > hope this helps > > Thibaut_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Mathieu Chappuis
2005-Dec-29 11:01 UTC
Re: Paginate do a Count(*) request before, how access that count value.
> Unless of course you need to query with conditions :)Plenty of conditions. up to 3 where id in (select x tables) ;)
Adam Denenberg
2005-Dec-29 13:55 UTC
Re: Paginate do a Count(*) request before, how access that count value.
here is how i do it page = (@params[:page] ||= 1).to_i perpage = (@session[:perpage] ||= 5).to_i offset = (page - 1) * perpage @messages = Message.find_by_sql(["select *,date_format(created_on,''%b %e %h:%i %p'') as fancydate from messages where user_id = ? order by created_on desc ",@session[:userid]]) @total = @messages.size.to_i @message_pages = Paginator.new(self,@messages.length,perpage,page) @messages = @messages[offset..(offset + perpage - 1)] @first_msg = @message_pages.current.first_item @last_msg = @message_pages.current.last_item @listing = ''Listing '' + @first_msg.to_s + '' - '' + @last_msg.to_s + '' of '' + @total.to_s This just displays "Listing 1-9 of 100" hope it helps. adam On 12/29/05, Mathieu Chappuis <mathieu.chappuis.lists-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > Unless of course you need to query with conditions :) > > Plenty of conditions. up to 3 where id in (select x tables) ;) > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails