liftedmedia-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Jun-19 03:46 UTC
variable conditions in find queries
What is the correct syntax for using variables in find conditions? I tried this but it doesnt seem to work, I also couldnt find any documentation online @vote = Vote.find(:all, :conditions => ''user_id = "@user.id"'', :order => "created_at DESC", :limit => "5" ) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
@vote = Vote.find(:all, :conditions => ["user_id = ? ", @user.id], :order => "created_at DESC", :limit => 5) If you want to put more conditions: :conditions => ["user_id = ? and group_id = ? ", @user.id, @group.id] ActiveRecord quotes(..security...) the condition for you claudio On Jun 19, 5:46 am, "liftedme...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <liftedme...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> What is the correct syntax for using variables in find conditions? > > I tried this but it doesnt seem to work, I also couldnt find any > documentation online > > @vote = Vote.find(:all, :conditions => ''user_id = "@user.id"'', :order > => "created_at DESC", :limit => "5" )--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---