Hi, I need to know why <%= SglineItem.find(1).sguser_id %> works but <%= SglineItem.find(:all, :conditions => "sguser_id #{params[:id]}").sguser_id %> does not. the second gives sguser_id is not valid. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
try <%= SglineItem.find(:all, :conditions => [''sguser_id =?'', params[:id] ] ).sguser_id %> hope it will work... :) Bala On Sat, Aug 30, 2008 at 3:31 PM, tyliong <tyliong-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi, > > I need to know why > > <%= SglineItem.find(1).sguser_id %> > > works but > > <%= SglineItem.find(:all, :conditions => "sguser_id > #{params[:id]}").sguser_id %> > > does not. the second gives sguser_id is not valid. > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Still gives "undefined method `sguser_id'' for #<Array:0xb6896af0>" From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] On Behalf Of bala kishore pulicherla Sent: Saturday, August 30, 2008 6:17 PM To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Subject: [Rails] Re: find syntax problem noob problem try <%= SglineItem.find(:all, :conditions => [''sguser_id =?'', params[:id] ] ).sguser_id %> hope it will work... :) Bala On Sat, Aug 30, 2008 at 3:31 PM, tyliong <tyliong-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: Hi, I need to know why <%= SglineItem.find(1).sguser_id %> works but <%= SglineItem.find(:all, :conditions => "sguser_id #{params[:id]}").sguser_id %> does not. the second gives sguser_id is not valid. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
:o try <% sgitem = SglineItem.find(:all, :conditions => [''sguser_id =?'', params[:id] ] ).sguser_id %> <% for item in sgitem %> <%= item %> <%end %> On Sat, Aug 30, 2008 at 3:58 PM, Tan YL <tyliong-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Still gives "undefined method `sguser_id'' for #<Array:0xb6896af0>" > > > > > > *From:* rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto: > rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] *On Behalf Of *bala kishore pulicherla > *Sent:* Saturday, August 30, 2008 6:17 PM > *To:* rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > *Subject:* [Rails] Re: find syntax problem noob problem > > > > try > <%= SglineItem.find(:all, :conditions => [''sguser_id =?'', params[:id] ] > ).sguser_id %> > > hope it will work... > > :) Bala > > On Sat, Aug 30, 2008 at 3:31 PM, tyliong <tyliong-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hi, > > I need to know why > > <%= SglineItem.find(1).sguser_id %> > > works but > > <%= SglineItem.find(:all, :conditions => "sguser_id > #{params[:id]}").sguser_id %> > > does not. the second gives sguser_id is not valid. > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Aug 30, 11:01 am, tyliong <tyli...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I need to know why > > <%= SglineItem.find(1).sguser_id %> > > works but > > <%= SglineItem.find(:all, :conditions => "sguser_id > #{params[:id]}").sguser_id %> > > does not. the second gives sguser_id is not valid.because find(1) (or find :first, ... ) return a single record from the database. find :all, returns an array. that array does not have a sguser_id method (even if the things in it do). Fred --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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=en -~----------~----~----~----~------~----~------~--~---
Yeah this was what I thought. The finds are two different things. How do I get it to return a record instead of an array while looking for a value not in the :id coloumn Fedrick? -----Original Message----- From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] On Behalf Of Frederick Cheung Sent: Saturday, August 30, 2008 7:54 PM To: Ruby on Rails: Talk Subject: [Rails] Re: find syntax problem noob problem On Aug 30, 11:01 am, tyliong <tyli...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I need to know why > > <%= SglineItem.find(1).sguser_id %> > > works but > > <%= SglineItem.find(:all, :conditions => "sguser_id > #{params[:id]}").sguser_id %> > > does not. the second gives sguser_id is not valid.because find(1) (or find :first, ... ) return a single record from the database. find :all, returns an array. that array does not have a sguser_id method (even if the things in it do). Fred --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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=en -~----------~----~----~----~------~----~------~--~---
On Aug 31, 5:00 pm, "Tan YL" <tyli...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Yeah this was what I thought. The finds are two different things. How do I > get it to return a record instead of an array while looking for a value not > in the :id coloumn Fedrick?use find :first instead of find :all (or just take the array and select the first item in it) (and of course you can use dynamic finders, find_by_xxx is analogous to find :first) Fred> > -----Original Message----- > From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > > [mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] On Behalf Of Frederick Cheung > Sent: Saturday, August 30, 2008 7:54 PM > To: Ruby on Rails: Talk > Subject: [Rails] Re: find syntax problem noob problem > > On Aug 30, 11:01 am, tyliong <tyli...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Hi, > > > I need to know why > > > <%= SglineItem.find(1).sguser_id %> > > > works but > > > <%= SglineItem.find(:all, :conditions => "sguser_id > > #{params[:id]}").sguser_id %> > > > does not. the second gives sguser_id is not valid. > > because find(1) (or find :first, ... ) return a single record from the > database. > find :all, returns an array. that array does not have a sguser_id > method (even if the things in it do). > > Fred--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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=en -~----------~----~----~----~------~----~------~--~---
short form: <%= params[:id] %> ;-) other than that: <%= SglineItem.find(:first, :conditions => ["sguser_id = ?", params[:id]]).sguser_id %> or <%= SglineItem.find_by_sguser_id(params[:id]).sguser_id %> you should be careful though because these queries could return nil if there''s no record with the given id in the db. also, if you use conditions you should use the array syntax (like above) to prevent sql injection. cheers gerold On 31 Aug., 18:16, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Aug 31, 5:00 pm, "Tan YL" <tyli...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Yeah this was what I thought. The finds are two different things. How do I > > get it to return a record instead of an array while looking for a value not > > in the :id coloumn Fedrick? > > use find :first instead of find :all (or just take the array and > select the first item in it) (and of course you can use dynamic > finders, find_by_xxx is analogous to find :first) > > Fred > > > > > -----Original Message----- > > From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > > > [mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] On Behalf Of Frederick Cheung > > Sent: Saturday, August 30, 2008 7:54 PM > > To: Ruby on Rails: Talk > > Subject: [Rails] Re: find syntax problem noob problem > > > On Aug 30, 11:01 am, tyliong <tyli...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hi, > > > > I need to know why > > > > <%= SglineItem.find(1).sguser_id %> > > > > works but > > > > <%= SglineItem.find(:all, :conditions => "sguser_id > > > #{params[:id]}").sguser_id %> > > > > does not. the second gives sguser_id is not valid. > > > because find(1) (or find :first, ... ) return a single record from the > > database. > > find :all, returns an array. that array does not have a sguser_id > > method (even if the things in it do). > > > Fred--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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=en -~----------~----~----~----~------~----~------~--~---