ct9a
2010-Aug-04 12:08 UTC
Need syntax help for the conditions argument in the find (ie Active Record) method
hi guys in relation to the "find" method in Active Record, can anyone tell me how to write the syntax for the following? 1) entries created within the past 2 hours, AND 2) entries that do not have a status of "Sold" at the moment, i have the following and i still get a syntax error of "NoMethodError: undefined method `%'' for #<Hash:0x000000083fa520>" @latest_entries = Books.find(:all, :conditions => [ { :created_at => (Time.now - 6 ) .. (Time.now) }, [ ''status_id != ?'' => Status.find_by_name(''sold'') ] ], :limit => 20, :order => ''created_at DESC'' ) Can someone please help me in terms of the syntax for the conditions argument? Thanks -- 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=en.
Frederick Cheung
2010-Aug-04 12:27 UTC
Re: Need syntax help for the conditions argument in the find (ie Active Record) method
On Aug 4, 1:08 pm, ct9a <anexi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> hi guys > > in relation to the "find" method in Active Record, can anyone tell me > how to write the syntax for the following? > > 1) entries created within the past 2 hours, AND > 2) entries that do not have a status of "Sold" > > at the moment, i have the following and i still get a syntax error of > "NoMethodError: undefined method `%'' for #<Hash:0x000000083fa520>" > > @latest_entries = Books.find(:all, > :conditions => [ > { > :created_at => (Time.now - 6 ) .. (Time.now) > }, > [ > ''status_id != ?'' => Status.find_by_name(''sold'') > ] > ], > :limit => 20, > :order => ''created_at DESC'' > ) > > Can someone please help me in terms of the syntax for the conditions > argument?You can''t mix and match the hash form and the array form of conditions - has to be all one or all the other. Fred> > Thanks-- 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=en.
ct9a
2010-Aug-04 12:45 UTC
Re: Need syntax help for the conditions argument in the find (ie Active Record) method
hi, Frederick, I was hoping to be able to mix hash and array conditions. After all, in an array , we could have hash element conditions. Anyway, your feedback along with my trials on the console further confirms that it cannot be done. I have fixed the problem in another manner (ie. use a clause for "live" status entries only). Thanks :) Case closed :) -- 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=en.