Search code examples
ruby-on-railsdev-to-production

How do I disable code from running in the development environment on Rails?


How can I remove code when my Rails app is in development mode? For example, I want to remove my Google Analytics reference when in development but have it render in the production environment.

Is there a solution that con be implemented in the views or the controllers? I can see a need for both.


Solution

  • <% if Rails.env == 'production' %>
      ...production code goes here...
    <% end %>
    

    This works for Rails 3. In older versions, user the environment variable RAILS_ENV.

    Robin