1

I am using Ruby on Rails 3 and I would like to set some global variable to use those everywhere in my application. In particular, the domain name.

If, for example, my website URL is

http://subname.domain.com

I would like to set or retrieve the subname.domain.com value in order to use that in my application like this

request_uri = "http://#{sub_domain_name}"

Where and how I have to state\initialize the sub_domain_name variable or other variables at all?

user502052
  • 14,803
  • 30
  • 109
  • 188
  • Possible duplicate of [Best way to create custom config options for my Rails app?](http://stackoverflow.com/questions/592554/best-way-to-create-custom-config-options-for-my-rails-app) – Salim Mahboubi Jan 07 '17 at 16:45

2 Answers2

2

Application controller is one place where you can set global variable. Just call a before_filter method in the landing function of the application.

If your question is specific to retrieving domain name of your application, you can use request.env['HTTP_HOST'].

Thanks....

Anubhaw
  • 5,978
  • 1
  • 29
  • 38
0

You can add an initialiser in config/initializers/ where you can declare and set the values of global variables / singletons, which would be available to your app.

rmk
  • 4,395
  • 3
  • 27
  • 32