Hi Champs, Hanging out with a problem.. I can find out the name of cities with City.find(:all).. I can find out the Bangalore city with City.find_by_name("Bangalore"). But what query i have to write to find the name of all cities except "Bangalore" ? I tried this but of no use .. City.find(:all, :conditions => { :name !"Bangalore" }) Can you people push me into the right direction. - Cheers -- 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.
Hemant Bhargava wrote:> Hi Champs, > > Hanging out with a problem.. > I can find out the name of cities with City.find(:all).. > I can find out the Bangalore city with City.find_by_name("Bangalore"). > But what query i have to write to find the name of all cities except > "Bangalore" ? > > I tried this but of no use .. City.find(:all, :conditions => { :name !> "Bangalore" }) > > Can you people push me into the right direction. > > > - CheersTry below syntax. City.find(:all, :conditions => [ "name != ''Bangalore''"] ) Thanks Brijesh Shah -- 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.
I am having Bangalore in an variable. I mean lets suppose selected_city. Then i tried this:- City.find(:all, :conditions => [ "name != selected_city" ] Nopes this is not working .. Brijesh Shah wrote:>> But what query i have to write to find the name of all cities except >> "Bangalore" ? >> >> I tried this but of no use .. City.find(:all, :conditions => { :name !>> "Bangalore" }) >> >> Can you people push me into the right direction. >> >> >> - Cheers > > Try below syntax. > > City.find(:all, :conditions => [ "name != ''Bangalore''"] ) > > > > Thanks > Brijesh Shah-- 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.
Hemant Bhargava wrote:> I am having Bangalore in an variable. I mean lets suppose selected_city. > Then i tried this:- > City.find(:all, :conditions => [ "name != selected_city" ] > > Nopes this is not working .. > > >Then try with this... City.find(:all, :conditions => [ "name != ?",selected_city ] selected_city must be variable. Thanks Brijesh Shah -- 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.
On Tue, Dec 29, 2009 at 2:27 AM, Hemant Bhargava <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>wrote:> I am having Bangalore in an variable. I mean lets suppose selected_city. > Then i tried this:- > City.find(:all, :conditions => [ "name != selected_city" ] > >Try the following: City.find( :all, :conditions => [ "name != selected_city" ] ) or City.find(:all, :conditions => [ "name != ?", selected_city ] ) -Conrad> Nopes this is not working .. > > > > Brijesh Shah wrote: > > >> But what query i have to write to find the name of all cities except > >> "Bangalore" ? > >> > >> I tried this but of no use .. City.find(:all, :conditions => { :name !> >> "Bangalore" }) > >> > >> Can you people push me into the right direction. > >> > >> > >> - Cheers > > > > Try below syntax. > > > > City.find(:all, :conditions => [ "name != ''Bangalore''"] ) > > > > > > > > Thanks > > Brijesh Shah > > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > > >-- 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.
Thanks Dude .. Worked .. Brijesh Shah wrote:> Hemant Bhargava wrote: >> I am having Bangalore in an variable. I mean lets suppose selected_city. >> Then i tried this:- >> City.find(:all, :conditions => [ "name != selected_city" ] >> >> Nopes this is not working .. >> >> >> > Then try with this... > > City.find(:all, :conditions => [ "name != ?",selected_city ] > > selected_city must be variable. > > Thanks > Brijesh Shah-- 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.
Thanks conrad, 2nd worked .. :) Conrad Taylor wrote:> On Tue, Dec 29, 2009 at 2:27 AM, Hemant Bhargava > <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>wrote: > >> I am having Bangalore in an variable. I mean lets suppose selected_city. >> Then i tried this:- >> City.find(:all, :conditions => [ "name != selected_city" ] >> >> > Try the following: > > City.find( :all, :conditions => [ "name != selected_city" ] ) > > or > > City.find(:all, :conditions => [ "name != ?", selected_city ] ) > > -Conrad >-- 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.