How to access default Rails sqlite db?

前端 未结 8 1641
清酒与你
清酒与你 2020-12-13 03:37

I would like to view the data in my DB while developing with Rails (actually in all 3 of them development, test and production). I have not touched the configs, so it should

相关标签:
8条回答
  • 2020-12-13 04:19

    You can have online access to your database if you use activeadmin.

    Just add the gem activeadmin-sqlpage:

    gem 'activeadmin-sqlpage'
    

    And create activeadmin page:

    # file app/admin/sql.rb
    ActiveAdmin::SqlPage::register
    

    Restart your server. Then go to admin panel and navigate the menu SQL. Enter any sql command and press Ctrl+Enter or Submit button.

    0 讨论(0)
  • 2020-12-13 04:23

    Open terminal and type this command. This will open a rails console to query the database.

    rails c
    

    To get list of all the models you can use the following command

    ActiveRecord::Base.connection.tables
    

    example: ["schema_migrations", "ar_internal_metadata", "categories", "items"]

    From the list of models, you can get first, last or all records.

    Category.all
    
    0 讨论(0)
提交回复
热议问题