Recently I read that the following find Type 1 ------ Post.find(:first, :conditions => [''status = ? and active = ?'', 1, 1]) can be written as Type 2 ------ Post.find(:first, :conditions => { :status => 1, :active => 1 }) But how do I include LIKE operator in Type 2 find? thanks -- Posted via http://www.ruby-forum.com/.
I never used but this may work Post.find(:first,:conditions[ ''status like ? and active like ?'', 1, 1]) On Sun, Jul 12, 2009 at 5:07 PM, Rails List < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Recently I read that the following find > > Type 1 > ------ > Post.find(:first, :conditions => [''status = ? and active = ?'', 1, 1]) > > can be written as > > Type 2 > ------ > Post.find(:first, :conditions => { :status => 1, :active => 1 }) > > > But how do I include LIKE operator in Type 2 find? > > thanks > -- > 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-/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 -~----------~----~----~----~------~----~------~--~---
sorry , conditions should be hash Post.find(:first,:conditions=>[ ''status like ? and active like ?'', 1, 1]) On Sun, Jul 12, 2009 at 5:14 PM, Narendra sisodiya <naren.sisodiya-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I never used but > > this may work Post.find(:first,:conditions[ ''status like ? and active like > ?'', 1, 1]) > > > On Sun, Jul 12, 2009 at 5:07 PM, Rails List < > rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > >> >> Recently I read that the following find >> >> Type 1 >> ------ >> Post.find(:first, :conditions => [''status = ? and active = ?'', 1, 1]) >> >> can be written as >> >> Type 2 >> ------ >> Post.find(:first, :conditions => { :status => 1, :active => 1 }) >> >> >> But how do I include LIKE operator in Type 2 find? >> >> thanks >> -- >> 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-/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 -~----------~----~----~----~------~----~------~--~---
2009/7/12 Rails List <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>:> > Recently I read that the following find > > Type 1 > ------ > Post.find(:first, :conditions => [''status = ? and active = ?'', 1, 1]) > > can be written as > > Type 2 > ------ > Post.find(:first, :conditions => { :status => 1, :active => 1 }) > > > But how do I include LIKE operator in Type 2 find?I believe that you cannot use LIKE in the Type 2 find. Colin
I like the type 2. But your example is a better candidate for named scope. like defining named scope ''active'' and using like, Post.active On Jul 12, 5:37 pm, Rails List <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Recently I read that the following find > > Type 1 > ------ > Post.find(:first, :conditions => [''status = ? and active = ?'', 1, 1]) > > can be written as > > Type 2 > ------ > Post.find(:first, :conditions => { :status => 1, :active => 1 }) > > But how do I include LIKE operator in Type 2 find? > > thanks > -- > Posted viahttp://www.ruby-forum.com/.