Hi, could u guys please help me with this syntax: SglineItem.find(:first, :conditions => {[''sguser_id =?'', params[:ad]], [''groceries_id =?'', params[:bd]]}) Full Code: ------------------------------------------------------------------------- def add_to_cart if SglineItem.find(:first, :conditions => {[''sguser_id =?'', params[:ad]],[''groceries_id =?'', params[:bd]]})== nil def add_to_cart if SglineItem.find(:first, :conditions => {[''sguser_id =?'', params[:ad]],[''groceries_id =?'', params[:bd]]})== nil item = SglineItem.new item.sguser_id= params[:ad] item.groceries_id=params[:bd] item.save! else item = SglineItem.find(:first, :conditions => {[''sguser_id =?'', params[:ad]],[''groceries_id =?'', params[:bd]]}) item.quantity +=1 end redirect_to :action => "panel", :id => params[:ad] end ---------------------------------------------------------------------------------------------------------------------- it gives undefined method `to_sym'' for ["sguser_id =?", "3"]:Array --~--~---------~--~----~------------~-------~--~----~ 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 2 Sep 2008, at 12:00, tyliong wrote:> > Hi, > > could u guys please help me with this syntax: > > SglineItem.find(:first, :conditions => {[''sguser_id =?'', params[:ad]], > [''groceries_id =?'', params[:bd]]}) >That''s just wrong. Either conditions is an array eg :conditions => [''foo=? and bar= ?'', foo, bar] or it''s a hash of column names and values :conditions => {:foo => foo, :bar =>bar} But not some mish-mash of the two. 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks that worked -----Original Message----- From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] On Behalf Of Frederick Cheung Sent: Tuesday, September 02, 2008 7:05 PM To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Subject: [Rails] Re: find conditions syntax problem On 2 Sep 2008, at 12:00, tyliong wrote:> > Hi, > > could u guys please help me with this syntax: > > SglineItem.find(:first, :conditions => {[''sguser_id =?'', params[:ad]], > [''groceries_id =?'', params[:bd]]}) >That''s just wrong. Either conditions is an array eg :conditions => [''foo=? and bar= ?'', foo, bar] or it''s a hash of column names and values :conditions => {:foo => foo, :bar =>bar} But not some mish-mash of the two. 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi, I would recommend referencing the Rails API when you have questions about the syntax and/or methods. Thus, it can be found at the following location: http://api.rubyonrails.com Good luck, -Conrad On Tue, Sep 2, 2008 at 4:06 AM, Tan YL <tyliong-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Thanks that worked > > -----Original Message----- > From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > [mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] On Behalf Of Frederick Cheung > Sent: Tuesday, September 02, 2008 7:05 PM > To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > Subject: [Rails] Re: find conditions syntax problem > > > > On 2 Sep 2008, at 12:00, tyliong wrote: > > > > > Hi, > > > > could u guys please help me with this syntax: > > > > SglineItem.find(:first, :conditions => {[''sguser_id =?'', params[:ad]], > > [''groceries_id =?'', params[:bd]]}) > > > > That''s just wrong. Either conditions is an array eg > > :conditions => [''foo=? and bar= ?'', foo, bar] > > or it''s a hash of column names and values > > :conditions => {:foo => foo, :bar =>bar} > > But not some mish-mash of the two. > > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---