I have a few pieces of code that I would like to display only in production, for instance, the showing of disqus comments. What is the best way to go about doing that? Currently I have:
<% if RAILS_ENV.eql?('production') %> disqus code here <% end %>
But I am not sure if that's the best method, or is that it? Seems pretty verbose and I would need this in a few different places in the application.
The effective check is
<% if Rails.env.production? %> disqus code here <% end %>
There is no need to put it as a constant in your environment.rb or an initializer. Just keep your code simple and use Rails.env.production? in your main code base I say.
I'd suggest writing a helper method in your application_helper.rb
file:
def render_disqus return '' unless Rails.env.production? #render disqus stuff here... end
Then, in your view it gets really simple:
<%= render_disqus %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With