I am trying to create a rails application that assigns one value to a variable when the environment is the development environment, and another value to that same variable w
You can do this with initializers.
# config/initializers/configuration.rb
class Configuration
class << self
attr_accessor :json_url
end
end
# config/environments/development.rb
# Put this inside the ______::Application.configure do block
config.after_initialize do
Configuration.json_url = 'http://test.domain.com'
end
# config/environments/production.rb
# Put this inside the ______::Application.configure do block
config.after_initialize do
Configuration.json_url = 'http://www.domain.com'
end
Then in your application, call the 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, this will hit the http://test.domain.com URL.
When you're running in production mode, this will hit the http://www.domain.com URL.