Rails3 Custom Environment Variables
I recently saw a question on Stack Overflow regarding custom variables that have different values based on which environment you are running for Rails.
It turns out it’s very easy to accomplish.
class << self
This gives you access to a Rails variable called Configuration.json_url. Now we just need to initialize this value in our environment files.
# Put this inside the ______::Application.configure block
Configuration.json_url = "http://test.domain.com"
Configuration.json_url = "http://www.domain.com"
Now you can test it in the Rails console.
$ rails console
$ RAILS_ENV=production rails console
Now your Rails app has access to these variables, so you can use them in your Controllers, Models or Views as needed.
[…] This post was mentioned on Twitter by Jason Noble, Jason Noble. Jason Noble said: Blog Post: Rails 3 custom per environment variables: http://jasonnoble.org/2011/02/rails3-custom-environment-variables.html […]
Hey I located your blog by mistake when i was searching Bing for this concern, I need to say your site is quite valuable I also like the theme, its cool!
I really learned about most of this, but that being said, I still believed it had been useful. Good blog!