Forum: Ruby on Rails how know the length of object?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F09468ba4111e3552b030695be24efd7?d=identicon&s=25 David Davox (davox)
on 2005-12-09 03:50
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.
01d7a451018ac15518f425078ef00c40?d=identicon&s=25 sitharus-rails (Guest)
on 2005-12-09 04:01
(Received via mailing list)
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 Hutchings
WebGenius Programmer
phillip@webgenius.co.nz
F09468ba4111e3552b030695be24efd7?d=identicon&s=25 David Davox (davox)
on 2005-12-09 04:23
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 Hutchings
> WebGenius Programmer
> phillip@webgenius.co.nz

its not working for me :S

i got this:
undefined method `length' for #<Expediente:0x59a73e0>

Expediente its the real name of the object:
<pre>@expediente = Expediente.find_by_expediente(params[:searchtext])
render_text @expediente.length</pre>
2ccb2f7699267d258faaafce4ee997df?d=identicon&s=25 codyfauser (Guest)
on 2005-12-09 05:22
(Received via mailing list)
David,

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


Cody


On 12/8/05, david davox <davidjgc@gmail.com> wrote:
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>


--
http://www.codyfauser.com
F09468ba4111e3552b030695be24efd7?d=identicon&s=25 David Davox (davox)
on 2005-12-09 05:32
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 <davidjgc@gmail.com> wrote:
>>
>> --
>> Posted via http://www.ruby-forum.com/.
>> _______________________________________________
>> Rails mailing list
>> Rails@lists.rubyonrails.org
>> http://lists.rubyonrails.org/mailman/listinfo/rails
>>
>
>
> --
> 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..
This topic is locked and can not be replied to.