Use different code for Rails 2 and Rails 3

When writing a piece of reusable code, you sometimes need to have separate code for Rails 2 and Rails 3. You can distinguish between Rails versions like this:

if Rails.version < '3' # mind the quotes
  # Rails 2 code goes here
else
  # Rails 3+ code goes here
end
Henning Koch Over 12 years ago