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.
Ead43bcb0202410540a6a7cee5955d46?d=identicon&s=25 Fresh Mix (giga)
on 2009-01-13 19:44
I use will_paginate to get results:

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

But how can I get a number of reults?
Ead43bcb0202410540a6a7cee5955d46?d=identicon&s=25 Fresh Mix (giga)
on 2009-01-13 20:41
How can I write it simple?

if @results.empty?
x = 0
else
x = 1
end
D6434aa0b7b350f8c3ed0119d81b2ead?d=identicon&s=25 Roy Pardee (rpardee)
on 2009-01-13 22:06
(Received via mailing list)
x = @results.empty? ? 1 : 0
A91bd6cef23eb3516245a092e196c4da?d=identicon&s=25 Maurício Linhares (mauricio)
on 2009-01-14 00: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)
9a2a53db8e9b4476038c94a64b32833f?d=identicon&s=25 Ryan Bigg (ryan-bigg)
on 2009-01-14 00: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 Bigg
Freelancer
http://frozenplague.net
2b1df44ef63bbf410976ef082d0d5d8b?d=identicon&s=25 Yacobus Reinhart (malioboro)
on 2009-01-14 02:24
James Bond 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]
5772c599ccab3081e0fffb1d54f3b6de?d=identicon&s=25 Andrew Timberlake (andrewtimberlake)
on 2009-01-14 04:19
(Received via mailing list)
On Wed, Jan 14, 2009 at 3:24 AM, Rails Terrorist <
rails-mailing-list@andreas-s.net> 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 Timberlake
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.