Monday, May 28, 2007

Rails AntiPattern: if environment == X

Lots of people will do this:

if ENV['RAILS_ENV'] == 'development' # or whatever
# do something
end


Don't ever do that. Instead, put it in environments/development.rb (or whichever).

2 comments:

  1. That looks like bad habits from perl.

    The problem with learning new languages is the old languages you already know.

    ReplyDelete
  2. It's a shortcut people take to debug stuff. It's not really a Perlism, as much as a sloppy-framework-ism. The environments files will automatically give you that same conditional execution, so explicitly specifying it is an error. People do it even though they know they shouldn't. It's the running a red light of Rails.

    ReplyDelete

Note: Only a member of this blog may post a comment.