Viewing the contents of tables in schema.rb in rails

user852974 picture user852974 · Aug 14, 2011 · Viewed 7.9k times · Source

I'm sorry if this is a stupid question, but in my schema.rb I have several tables like

  create_table "messages", :force => true do |t|
    t.integer  "user_id",            :null => false
    t.string   "message",            :null => false
    t.datetime "created_at",         :null => false
    t.string   "photo_file_name"
    t.string   "photo_content_type"
    t.integer  "photo_file_size"
    t.datetime "photo_updated_at"
  end

Is it possible to view the contents of each table i.e view each message and associated user id, message content, time created at, linked image, etc?

Thanks

Answer

coreyward picture coreyward · Aug 14, 2011

A database schema represents the structure of the database, not the content of it.

If you want to access the content in your database, you would query it to do so. You can do that via command line clients (running $ rails dbconsole will try to open one for the configured database) or graphical tools like Sequel Pro (for MySQL on Mac OS X).

You can also get this through your Rails application by running $ rails console and then using the methods available through ActiveRecord (e.g. Post.all or User.where(:name => 'Billy').limit(5)).