How know the length of object?


#1

Hi, maybe a newbbie question… if i have this code:

@books = Book.find(params[:searchtext])

how can know how many records have the @books object?

Thnx for the help.


#2

On 9/12/2005, at 3:50 PM, david davox wrote:

how can know how many records have the @books object?

@books.length seems to work for me.

Phillip H.
WebGenius Programmer
removed_email_address@domain.invalid


#3

David,

You’re only finding a single object. You’d want
find_all_by_expediente(params[:searchtext])

Cody

On 12/8/05, david davox removed_email_address@domain.invalid wrote:


Posted via http://www.ruby-forum.com/.


Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails


http://www.codyfauser.com


#4

sitharus-rails wrote:

On 9/12/2005, at 3:50 PM, david davox wrote:

how can know how many records have the @books object?

@books.length seems to work for me.

Phillip H.
WebGenius Programmer
removed_email_address@domain.invalid

its not working for me :S

i got this:
undefined method `length’ for #Expediente:0x59a73e0

Expediente its the real name of the object:

@expediente = Expediente.find_by_expediente(params[:searchtext])
render_text @expediente.length

#5

codyfauser wrote:

David,

You’re only finding a single object. You’d want
find_all_by_expediente(params[:searchtext])

Cody

On 12/8/05, david davox removed_email_address@domain.invalid wrote:


Posted via http://www.ruby-forum.com/.


Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails


http://www.codyfauser.com

yes!:. thnx :slight_smile:
by the way, i found this (from the friends in the irc channel):

render_text @expediente.to_a.size #return how many items are in the
instance, its like a cast to Array…