Where can I store site-wide variables in Rails 4?

Viewed 22806

I am new to Rails and come from a ColdFusion background, where we would store global / site-wide variables in the 'application' scope. This persists the variable across any view or controller. Does Rails 4 have an equivalent functionality for this type of thing?

The site-wide variable won't typically change often so it doesn't need protecting in any way.

For example, in my situation, I want to store the website's domain name. One for testing and one for live environments. Localhost for development and xxxxxx.com for production.

Any tips or pointers would help. I have Googled this extensively and solutions seem to be far too complicated to achieve what seems to be such a trivial task. What's the best elegant solution for Rails 4?

5 Answers

In rails there is gem named as

gem 'dotenv-rails'

By using it we can assign the variables to system level and used in application.

By using simple steps First create a simple filed in system level at any place with named extension .env

//in application.rb        
require 'dotenv'
Dotenv.load('path-of-your-file.env')

And restart your application

Source Please got the link for the desscription of dot env gem

Related