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. -- Posted via http://www.ruby-forum.com/.
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-O2c5G25DRx+BSvQ9g6pY6g@public.gmane.org
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-O2c5G25DRx+BSvQ9g6pY6g@public.gmane.orgits 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> -- Posted via http://www.ruby-forum.com/.
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-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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-O2c5G25DRx+BSvQ9g6pY6g@public.gmane.org > > 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> > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- http://www.codyfauser.com
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-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> -- >> Posted via http://www.ruby-forum.com/. >> _______________________________________________ >> Rails mailing list >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> > > > -- > http://www.codyfauser.comyes!:. 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.. -- Posted via http://www.ruby-forum.com/.