Forum: Ruby on Rails Number of entries

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Fresh M. (Guest)
on 2009-01-13 20:44
I use will_paginate to get results:

@results = Users.paginate(:all, :conditions => "...

But how can I get a number of reults?
Fresh M. (Guest)
on 2009-01-13 21:41
How can I write it simple?

if @results.empty?
x = 0
else
x = 1
end
Roy P. (Guest)
on 2009-01-13 23:06
(Received via mailing list)
x = @results.empty? ? 1 : 0
Maurício L. (Guest)
on 2009-01-14 01:04
(Received via mailing list)
And instead of empty, you should use "blank?", that would work even if
@results is "nil"

x = @results.blank? ? 1 : 0

-
Maurício Linhares
http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/
(en)
Ryan B. (Guest)
on 2009-01-14 01:22
(Received via mailing list)
@results should never be nil unless he's forgotten to define the
variable which would just be Bad Programming.
-----
Ryan B.
Freelancer
http://frozenplague.net
Yacobus R. (Guest)
on 2009-01-14 03:24
James B. wrote:
> I use will_paginate to get results:
>
> @results = Users.paginate(:all, :conditions => "...
>
> But how can I get a number of reults?

to get a number of result you can get it by :

@results.size

if @results.size < 1
flash[:notice] = "There's no result so its data is empty."
end


- Ruby Servant -
[Some times i am terrorist of it]
Andrew T. (Guest)
on 2009-01-14 05:19
(Received via mailing list)
On Wed, Jan 14, 2009 at 3:24 AM, Rails T. <
removed_email_address@domain.invalid> wrote:

> @results.size
>
> >
>
@results.size will give you the number in that 'page'
@results.total_entries will give you the total number of results you're
paginating over

--
Andrew T.
http://ramblingsonrails.com
http://www.linkedin.com/in/andrewtimberlake

"I have never let my schooling interfere with my education" - Mark Twain
This topic is locked and can not be replied to.