Hi there, I try to make simple search items in database, but unfortunately, I cant to get the results... always. I am trying to search the items with using of following command: @data = Data.find(:all, :conditions => { :name => ''abcd'' }) But unfortunately, I am not getting any result... Of course, the item with the name ''abcd'' in database exist... The weird is this, that when I try to edit the command: @data = Data.find(:all, :conditionsxxx => { :name => ''abcd'' }) And I not getting any error message... so I don''t now, where could be error... And when I set up this command: @data = Data.all everything work... So I am confused, where is fault... I''ll be happy for every help! Thanks, M. -- 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.
Bryan Crossland
2011-Mar-10 19:10 UTC
Re: Rails 3 and problem with conditions - no results
On Thu, Mar 10, 2011 at 12:36 PM, Manny 777 <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi there, > I try to make simple search items in database, but unfortunately, I > cant to get the results... always. I am trying to search the items with > using of following command: > > @data = Data.find(:all, :conditions => { :name => ''abcd'' }) > > But unfortunately, I am not getting any result... Of course, the item > with the name ''abcd'' in database exist... The weird is this, that when I > try to edit the command: > >The data in your database may have spaces after it that you are not seeing. The find is not returning what you expect because it is trying to match an exact string. ''abcd'' does not equal ''abcd ''. Check the data in your database to make sure there are no spaces after it. A simple check would be to run the following in irb: Data.find(:all).each {|i| puts "#{i.name}|" } If the names don''t print out with the pipe (|) as the last character in the string then you have a space at the end of the name. B. -- 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.
Martin Streicher
2011-Mar-11 00:18 UTC
Re: Rails 3 and problem with conditions - no results
The preferred technique for Rails 3 is Data.where :name => ''abcd'' I agree with Bryan you should check your data. You may need to strip the string of blanks before you save to the database. On Mar 10, 2:10 pm, Bryan Crossland <bacrossl...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Thu, Mar 10, 2011 at 12:36 PM, Manny 777 <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > > Hi there, > > I try to make simple search items in database, but unfortunately, I > > cant to get the results... always. I am trying to search the items with > > using of following command: > > > @data = Data.find(:all, :conditions => { :name => ''abcd'' }) > > > But unfortunately, I am not getting any result... Of course, the item > > with the name ''abcd'' in database exist... The weird is this, that when I > > try to edit the command: > > The data in your database may have spaces after it that you are not seeing. > The find is not returning what you expect because it is trying to match an > exact string. ''abcd'' does not equal ''abcd ''. Check the data in your database > to make sure there are no spaces after it. A simple check would be to run > the following in irb: > > Data.find(:all).each {|i| puts "#{i.name}|" } > > If the names don''t print out with the pipe (|) as the last character in the > string then you have a space at the end of the name. > > B.-- 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.