# How know the length of object?

**URL:** <https://www.ruby-forum.com/t/how-know-the-length-of-object/49837>\
**Category:** Rails\
**Created:** [December 9, 2005, 3:50am UTC](https://www.ruby-forum.com/t/how-know-the-length-of-object/49837 "2005-12-09T03:50:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![davox](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/90ced4/32.png) [@davox](https://www.ruby-forum.com/u/davox)\
**Post date:** [December 9, 2005, 3:50am UTC](https://www.ruby-forum.com/t/how-know-the-length-of-object/49837/1 "2005-12-09T03:50:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![davox](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/90ced4/32.png) [@davox](https://www.ruby-forum.com/u/davox)\
**Post date:** [December 9, 2005, 4:01am UTC](https://www.ruby-forum.com/t/how-know-the-length-of-object/49837/2 "2005-12-09T04:01:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![davox](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/90ced4/32.png) [@davox](https://www.ruby-forum.com/u/davox)\
**Post date:** [December 9, 2005, 5:22am UTC](https://www.ruby-forum.com/t/how-know-the-length-of-object/49837/3 "2005-12-09T05:22:27Z")

</div>

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](mailto:removed_email_address@domain.invalid) wrote:

> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

–  
[http://www.codyfauser.com](http://www.codyfauser.com)

---

<div class="post-metadata">

**Author:** ![davox](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/90ced4/32.png) [@davox](https://www.ruby-forum.com/u/davox)\
**Post date:** [December 9, 2005, 4:23am UTC](https://www.ruby-forum.com/t/how-know-the-length-of-object/49837/4 "2005-12-09T04:23:39Z")

</div>

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
```

---

<div class="post-metadata">

**Author:** ![davox](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/90ced4/32.png) [@davox](https://www.ruby-forum.com/u/davox)\
**Post date:** [December 9, 2005, 5:32am UTC](https://www.ruby-forum.com/t/how-know-the-length-of-object/49837/5 "2005-12-09T05:32:42Z")

</div>

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](mailto:removed_email_address@domain.invalid) wrote:
> 
> > –  
> > Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> > 
> > * * *
> > 
> > Rails mailing list  
> > removed\_email\_address@domain.invalid  
> > [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)
> 
> –  
> [http://www.codyfauser.com](http://www.codyfauser.com)

yes!:. thnx 🙂  
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…
