**this is the error: undefined method `to_i'' for ["5"]:Array **this is the code: sql = ActiveRecord::Base.connection(); @loo = sql.execute("select count(name) from data1.items").fetch_row; @loo = @loo.to_i Plz help; it is urgent. regards, INDRANIL MUKHERJEE -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=.
@loo = @loo.first.to_i On Wed, Nov 18, 2009 at 6:26 PM, INDRANIL MUKHERJEE < indranil.since87-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> **this is the error: > > undefined method `to_i'' for ["5"]:Array > > > **this is the code: > > sql = ActiveRecord::Base.connection(); > @loo = sql.execute("select count(name) from data1.items").fetch_row; > > @loo = @loo.to_i > > > Plz help; it is urgent. > > regards, > > INDRANIL MUKHERJEE > > -- > > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=. > > >-- Adam Jones Digirati Limited NZ adam-K36Kqf6HJK7JKwlM9GxbOw@public.gmane.org P 027 233 6933 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=.
you are getting that error because this> @loo = sql.execute("select count(name) from data1.items").fetch_row;is returning the count as an array. to get this working you need to call @loo.first.to_i but why are you not using Item.count or Item.count(:name) that will straight away give you the count number that you dont have to convert to integer as well nas http://nasir.wordpress.com http://twitter.com/_nasj http://github.com/nas On Nov 18, 5:26 am, INDRANIL MUKHERJEE <indranil.sinc...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> **this is the error: > > undefined method `to_i'' for ["5"]:Array > > **this is the code: > > sql = ActiveRecord::Base.connection(); > @loo = sql.execute("select count(name) from data1.items").fetch_row; > > @loo = @loo.to_i > > Plz help; it is urgent. > > regards, > > INDRANIL MUKHERJEE-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=.