1

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

user852974
  • 2,242
  • 10
  • 41
  • 65

4 Answers4

11

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)).

coreyward
  • 77,547
  • 20
  • 137
  • 166
0

You can use gem "annotate". It is very helpful for me.

0

you can use modelname.all for eg: Country.all will give you all entries in your table

-1

For viewing the table structure on the rails console only need to run the table name eg If there is a table with name country. only run the 'Country '

2.4.4 :004 > Country => Country(id: integer, name: string, percentage: string, created_at: datetime, updated_at: datetime, is_sync: boolean) 2.4.4 :005 >

Anupam
  • 21
  • 3