0

For some reason whenever I want to query data from the database I get the name of my table and then bunch of numbers. Like below

#<My_Table:0x007fa706835b30>

Here is my code:

#!/usr/bin/env ruby

require 'rubygems'
require 'active_record' 
require 'mysql2'

#establish the connection.
ActiveRecord::Base.establish_connection(
:adapter => "mysql2",
:database => "test",
:username => "root",
:password => "",
:host => "localhost"
)

#create a class inherit with activerecord base class.
class My_Table < ActiveRecord::Base
end

#My_Table.create(:FirstName => 'me', :LastName => "myself", :Age => "19") 
#you = My_Table.find(:first)
#puts you

user = My_Table.select("FirstName, LastName, Age")
puts user 

Output:

#<My_Table:0x007fa7068158d0>
#<My_Table:0x007fa7068378e0>
#<My_Table:0x007fa7068372f0>
#<My_Table:0x007fa706836d00>
#<My_Table:0x007fa706836710>
#<My_Table:0x007fa706836120>
#<My_Table:0x007fa706835b30>

Any ideas would be greatly appreciated..

Thank you!

1 Answer 1

0

What you see is each Active Record created MyTable object for every row that is matched with your query. The numbers are a unique ID for each object.

To see what is inside the object, use

puts user.inspect

You will have accessors (Mytable.column, Mytable.column=) for each column by default for each of these objects.

1
  • Glad to hear! If it worked could you mark my response as the solution so the question can be closed?
    – Nikhil
    Mar 21, 2012 at 4:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.