Trying to print on the console a single column from a db

Since you are using :limit => 1 you are not going to get an array, just a single object. Remember that in ruby, the @ signifies an instance variable, and does not signify that the variable holds an array as it does in perl. This will work:

def self.START

    all = MyDb.find_all_by_server_name('myserver', :limit => 1)

    puts all[:server_name]

end

Brent Brent wrote:

Sorry, my bad, when I first looked at this I read it as @all, but the solution is the same, you are getting a single object rather than an array. Hope this helps.

William Pratt wrote:

btw, you can also use accessor methods like:


    def self.START
all = MyDb.find_all_by_server_name('myserver', :limit => 1)
puts all.server_name
end

William Pratt wrote:

Huh? That's not the behavior I get. I get an array with one element if I use find(:all) or find_all_by_blah, with :limit => 1

You are right. First off, I have never tried using an find_all_by_foo method with a :limit of one, but based on the output he was seeing, it looked like a single object, although looking at it again, it is a single element array. Sorry for the confusion.

Bob Showalter wrote: