Number of entries

I use will_paginate to get results:

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

But how can I get a number of reults?

How can I write it simple?

if @results.empty?
x = 0
else
x = 1
end

x = @results.empty? ? 1 : 0

@results should never be nil unless he’s forgotten to define the
variable which would just be Bad Programming.

Ryan B.
Freelancer

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)

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]

On Wed, Jan 14, 2009 at 3:24 AM, Rails T. <
[email protected]> 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