Rails 3 and problem with conditions - no results

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.

On Thu, Mar 10, 2011 at 12:36 PM, Manny 777 [email protected]
wrote:

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.

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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs