Always Get Better

Displaying Production-Only Markup in Rails

If you are running something like Google Analytics on your website, you probably don’t want its associated JavaScript code to appear in your web browser while you’re developing (it would skew your statistics). In Rails, it is incredibly simple to block off a segment of markup for specific environments by using the Rails.env variable.

If you are using Passenger, your rails environment is set to ‘production’ by default, making it very easy to do something like this:

Tags:

2 Responses to “Displaying Production-Only Markup in Rails”

  1. […] Conditional Statements Let’s go a step further. Suppose we have Google Analytics and only want the JavaScript to run when our site has been deployed to production (I covered a similar technique earlier this year using Ruby on Rails). […]

  2. […] application during the Christmas break in 2010, but in 2011 I moved that site into production and wrote a little bit about separating production and development values (a feat I repeated for the Play! framework, which I actually like, later in the year). I think the […]

Leave a Reply

Notice: Undefined variable: user_ID in /usr/share/nginx/html/wp-content/themes/getbetter/comments.php on line 65