I want to display the current host and database names in a view.
Where can I get these names?
Are there some predefined environment or global variables?
Rails uses an SQLite3 database for data storage by default because it is a zero configuration database that just works. Rails also supports MySQL (including MariaDB) and PostgreSQL "out of the box", and has plugins for many database systems. If you are using a database in a production environment Rails most likely has an adapter for it.
The host of a request is checked against the hosts entries with the case operator ( #=== ), which lets hosts support entries of type Regexp , Proc and IPAddr to name a few. Here is an example with a regexp. # Allow requests from subdomains like `www.product.com` and # `beta1.product.com`. Rails.application.config.hosts << /.*\.product\.com/
Ruby on Rails recommends to create three databases - a database each for development, testing, and production environment. According to convention, their names should be − You should initialize all three of them and create a user and password for them with full read and write privileges.
This same information can be stored in a URL and provided via an environment variable like this: The config/database.yml file contains sections for three different environments in which Rails can run by default: The development environment is used on your development/local computer as you interact manually with the application.
With Rails 3 you can use
Rails.configuration.database_configuration[Rails.env]
or
Rails.application.config.database_configuration[Rails.env]
or
ActiveRecord::Base.connection_config
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With