Number of entries


#1

I use will_paginate to get results:

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

But how can I get a number of reults?


#2

How can I write it simple?

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


#3

x = @results.empty? ? 1 : 0


#4

@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


#5

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)


#6

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]

#7

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