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!
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
You will have accessors (Mytable.column, Mytable.column=) for each column by default for each of these objects.