简体   繁体   中英

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.

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

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

Robin

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM