I want to load jQuery UI via Google CDN if in production and locally if in development. So in my application.html.erb layout, I've got to know whether I'm in production or dev. Is there a variable I can check?
Asked
Active
Viewed 1.4k times
3 Answers
38
To expand a bit on Paritosh's answer, Rails.env.production?
and Rails.env.development?
will return true/false depending on which environment you're using.
These methods are defined in the StringInquirer
class in the ActiveSupport
module. See them here.

Zajn
- 4,078
- 24
- 39
-
1Where can I see the source of these functions? must be a meta programming thing.any idea? – shajin Jan 28 '14 at 08:25
-
1Yes, it is. Have a look [here](https://github.com/rails/rails/blob/e20dd73df42d63b206d221e2258cc6dc7b1e6068/activesupport/lib/active_support/string_inquirer.rb). – Zajn Jan 28 '14 at 14:43
9
To riff off of the previous answer, you can scope your check to specific environments like so:
Rails.env.development?
where development?
is the name of the environment you want to check.
Also something else I tend to do is if I am checking multiple environments you may want to do something like:
if %w(staging production).include?(Rails.env)
# do something
end

Matt Polito
- 9,588
- 2
- 19
- 13
2
use Rails.env
, it will give you environment you are working on.

Kyle
- 21,978
- 2
- 60
- 61

Paritosh Singh
- 6,288
- 5
- 37
- 56
-
1Thanks, that's what I was looking for. It appears to return a StringInquirer. Is there a particularly way we're expected to query this object? – at. Sep 28 '12 at 19:59
-