Search code examples
ruby-on-rails

Displaying host and database names in Rails


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?


Solution

  • You can create a rails configuration object and obtain the necessary information from it:

    config   = Rails::Configuration.new
    host     = config.database_configuration[RAILS_ENV]["host"]
    database = config.database_configuration[RAILS_ENV]["database"]
    

    See the documentation for Rails::Configuration for details.