Rails 3 / Setting Custom Environment Variables -


i trying create rails application assigns 1 value variable when environment development environment, , value same variable when environment production environment. want specify both values in code (hardwired), , have rails know value assign variable based on environment running. how do this?

in case important, later access variable , return value in class method of model.

you can initializers.

# config/initializers/configuration.rb class configuration   class << self     attr_accessor :json_url   end end  # config/environments/development.rb #  put inside ______::application.configure block config.after_initialize   configuration.json_url = 'http://test.domain.com' end  # config/environments/production.rb #  put inside ______::application.configure block config.after_initialize   configuration.json_url = 'http://www.domain.com' end 

then in application, call variable configuration.json_url

# app/controller/listings_controller.rb def grab_json   json_path = "#{configuration.json_url}/path/to/json" end 

when you're running in development mode, hit http://test.domain.com url.

when you're running in production mode, hit http://www.domain.com url.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -