Find conditions syntax problem

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

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

Thanks that worked

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