This is my old blog. My current writing is here:

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.


Are you down with SVN? Yeah, you know me!

./script/plugin install -x

Think source control is for the weak?

./script/plugin install


Rails Environments drops five hot new methods in your lap:

if Rails.production?
elsif Rails.development?
elsif Rails.test?
elsif Rails.none?
  'Oh, You Gotta Be Kidding Me'
  "Dude, what the hell: #{Rails.environment}"

Not complicated, sure, but it makes my code pretty. Ponies!

4 Responses to “Rails Environments: a plugin for, well, Rails”

  1. Paolo Dona Says:

    Simple and effective. Thanks a lot man. It’s weird such a function is not bundled with rails itself, as it really should.

  2. Jon Maddox Says:

    excellent. I do this all the time. This is handy.

  3. nixxbox writes » Blog Archive » MySQL, Rails, Unit Tests, and Foreign Keys Says:

    [...] 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: [...]

  4. Panasonic Youth – Staging Environments in Rails Says:

    [...] 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 [...]