Rails Environments: a plugin for, well, Rails
This one’s simple. Sometimes I need to know what environment Rails is running in (for example, so I can display additional debugging information, or not link to the HTTPS version of an action), and typing out ENV['RAILS_ENV'] is a hassle and looks ugly. Hence, this plugin.
Installation
Are you down with SVN? Yeah, you know me!
./script/plugin install -x http://svn.codahale.com/rails_environments/trunk
Think source control is for the weak?
./script/plugin install http://svn.codahale.com/rails_environments/trunk
Usage
Rails Environments drops five hot new methods in your lap:
if Rails.production?
'Production'
elsif Rails.development?
'Development'
elsif Rails.test?
'Test'
elsif Rails.none?
'Oh, You Gotta Be Kidding Me'
else
"Dude, what the hell: #{Rails.environment}"
end
Not complicated, sure, but it makes my code pretty. Ponies!
June 8th, 2006 at 5:40am
Simple and effective. Thanks a lot man. It’s weird such a function is not bundled with rails itself, as it really should.
August 2nd, 2006 at 3:32pm
excellent. I do this all the time. This is handy.
December 7th, 2006 at 9:14am
[...] See, it’s that easy. Note, that the code above requires the Rails environments plugin. It’s not absolutely necessary, but makes the code look nicier. Without this plugin one would have to test for environment like this: [...]
March 11th, 2008 at 6:31am
[...] to have less constants in my code, as I feel all caps detracts from the beauty of Ruby. You can use Coda’s plugin or write your own in probably 5 minutes. Since you have a level of indirection around your [...]