Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 594
hectorsq Avatar asked Nov 06 '08 00:11

hectorsq


People also ask

What type of database does rails use?

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.

How to check the host of a request in rails?

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/

How many databases should I create in Ruby on rails?

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.

What is the default environment for a rails database?

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.


1 Answers

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 
like image 92
Fernando Almeida Avatar answered Sep 25 '22 10:09

Fernando Almeida