How know the length of object?

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.

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
[email protected]

David,

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

Cody

On 12/8/05, david davox [email protected] wrote:


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


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails


http://www.codyfauser.com

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
[email protected]

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

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 [email protected] wrote:


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


Rails mailing list
[email protected]
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…