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.
David D. (Guest)
on 2005-12-09 04: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.
sitharus-rails (Guest)
on 2005-12-09 05: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 H.
WebGenius Programmer
removed_email_address@domain.invalid
David D. (Guest)
on 2005-12-09 05: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 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:
<pre>@expediente = Expediente.find_by_expediente(params[:searchtext])
render_text @expediente.length</pre>
codyfauser (Guest)
on 2005-12-09 06: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 <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
David D. (Guest)
on 2005-12-09 06: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 <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 :)
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.