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 <[email protected]> wrote: > On Thu, Mar 10, 2011 at 12:36 PM, Manny 777 <[email protected]> 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 [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

