Posted about 11 years ago. Visible to the public. Repeats.

Detect the current Rails environment from JavaScript or CSS

Detecting if a Javascript is running under Selenium WebDriver is super-painful Archive . It's much easier to detect the current Rails environment instead.

You might be better of checking against the name of the current Rails environment. To do this, store the environment name in a data-environment of your <body>. E.g., in your application layout:

<body data-environment=<%= Rails.env %>>

Now you can say in a piece of Javascript:

if (document.body.dataset.environment == 'test') { // Code that should happen in Selenium tests } else { // Code that should happen for other environments }

Or in your CSS / Sass:

body[data-environment="test"] { * { text-transform: none !important; } }

See also

Does your version of Ruby on Rails still receive security updates?
Rails LTS provides security patches for unsupported versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2).

Owner of this card:

Henning Koch
Last edit:
9 days ago
by Henning Koch
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Henning Koch to makandra dev
This website uses short-lived cookies to improve usability.
Accept or learn more