user852974
user852974

Reputation: 2282

Viewing the contents of tables in schema.rb in rails

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

Upvotes: 1

Views: 8296

Answers (4)

Nidhi Tyagi
Nidhi Tyagi

Reputation: 3

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

Upvotes: 0

Anupam
Anupam

Reputation: 21

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 >

Upvotes: -1

Alla Johnson
Alla Johnson

Reputation: 3

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

Upvotes: 0

coreyward
coreyward

Reputation: 80041

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

Upvotes: 11

Related Questions