Use different code for Rails 2 and Rails 3

Updated . Posted . Visible to the public.

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
Profile picture of Henning Koch
Henning Koch
Last edit
License
Source code in this card is licensed under the MIT License.
Posted by Henning Koch to makandra dev (2011-08-29 13:27)