在rails中查看schema.rb中表的内容

use*_*974 1 ruby schema ruby-on-rails schema.rb database-schema

如果这是一个愚蠢的问题,我很抱歉,但在我的schema.rb中我有几个表

  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
Run Code Online (Sandbox Code Playgroud)

是否可以查看每个表的内容,即查看每个消息和相关的用户ID,消息内容,创建时间,链接图像等?

谢谢

cor*_*ard 11

一个数据库模式代表了数据库的结构,而不是它的内容.

如果要访问数据库中的内容,可以查询它.您可以通过命令行客户端(运行$ rails dbconsole将尝试为已配置的数据库打开一个)或图形工具(如Sequel Pro(适用于Mac OS X上的MySQL))执行此操作.

您还可以通过运行$ rails console然后使用ActiveRecord提供的方法(例如Post.allUser.where(:name => 'Billy').limit(5))来通过Rails应用程序获取此信息.