I would like to limit the results returned by the category_id. I can manually insert the category_id :conditions => [''category_id = 1''] but I would like it to respond to the input from the search form instead. :conditions => ["category_id like ?", params[:category_id]+"%"] :conditions => ["category_id ?"] I can''t figure this one out. The view is: <% form_tag search_dudes_path do -%> <p> <%= collection_select(:dude, :category_id, Category.all, :id, :name) %> </p> . . . -- Posted via http://www.ruby-forum.com/. -- 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.
Sean Six wrote:> I would like to limit the results returned by the category_id. I can > manually insert the category_id :conditions => [''category_id = 1''] but I > would like it to respond to the input from the search form instead. > > :conditions => ["category_id like ?", params[:category_id]+"%"] > :conditions => ["category_id ?"] > > I can''t figure this one out. > The view is: > > <% form_tag search_dudes_path do -%> > <p> > <%= collection_select(:dude, :category_id, Category.all, :id, :name) > %> > </p> > . > . > .Why are you using LIKE with a (presumably numeric) ID? Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- 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.
It seems most reasonable to me that it would be :conditions => ["category_id = ?", category_id] But that gives me an error. undefined local variable or method `category_id'' for #<DudesController:0xb6eb3960> -- Posted via http://www.ruby-forum.com/. -- 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.
[Please quote properly in your replies.] Sean Six wrote:> It seems most reasonable to me that it would be > :conditions => ["category_id = ?", category_id] > > But that gives me an error. > > undefined local variable or method `category_id'' for > #<DudesController:0xb6eb3960>So don''t use an undefined variable. This is a Ruby error. It has nothing to do with your SQL query string. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- 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.
category_id = params[:category_id] @dudes = Dude.find(:all, :conditions => ["category_id = ?", category_id]) This is returning no results. -- Posted via http://www.ruby-forum.com/. -- 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.
Alight. :conditions => ["category_id = :category_id", params[:dude]] -- Posted via http://www.ruby-forum.com/. -- 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.
Sean Six wrote:> category_id = params[:category_id] > > @dudes = Dude.find(:all, > :conditions => ["category_id = ?", category_id]) > > This is returning no results.Then there are no results to return. This is the correct syntax. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- 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.
joshmckin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2010-Feb-02 18:55 UTC
Re: Conditions parameter for find
You can also use: @dudes = Dude.find(:all, :conditions => {:category_id => category_id}) On Feb 2, 12:28 am, Marnen Laibow-Koser <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Sean Six wrote: > > category_id = params[:category_id] > > > @dudes = Dude.find(:all, > > :conditions => ["category_id = ?", category_id]) > > > This is returning no results. > > Then there are no results to return. This is the correct syntax. > > Best, > -- > Marnen Laibow-Koserhttp://www.marnen.org > mar...-sbuyVjPbboAdnm+yROfE0A@public.gmane.org > -- > Posted viahttp://www.ruby-forum.com/.-- 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.