Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to check the database name that ActiveRecord uses

In database.yml you define all the settings. How can I access those settings from ruby? I've looked in App::Application::config, but can't find it there. Also, I remember people were able to configure database settings without yaml, does anyone know how?

like image 504
m33lky Avatar asked Apr 03 '12 21:04

m33lky


People also ask

What database does Rails use?

Rails defaults to using a SQLite database when creating a new project, but you can always change it later.

What does ActiveRecord base mean?

ActiveRecord::Base indicates that the ActiveRecord class or module has a static inner class called Base that you're extending.

Where is the database stored in Rails?

By default, Rails uses SQLite3. The database files are stored in the /db directory in the root of your app. There should be a file called development.


1 Answers

Rails.configuration.database_configuration 

This will give you a hash table with the configurations for each of your environments. E.g. to get your development database name:

Rails.configuration.database_configuration["development"]["database"] 
like image 145
tsherif Avatar answered Sep 22 '22 08:09

tsherif