What is a "common" practice / technique for displaying only one log message?

I am running Ruby on Rails 3.1. I would like to know the "usually" practice / technique used to set a variable (for example status = 'loaded'

) in a partilal templates file so that the variable does not have to be re-set anytime that partial template is rendered. That is, I have a partial template file that is displayed multiple times in one request, and I would like to display a warning message in the log only once (that is, once) even if the partial template is loaded more than once ... for performance reasons (or for "perfectionism" ...).

In a few words, I would like to display the "Warning" message only once in the log file.

How can I (easily) do this?

+3


source to share


1 answer


Yes, it is possible to turn off the logging for some messages in your log, but this approach is not very simple (see this question ) and even harmful in your case, you have to ask yourself WHY do you want this? You may be doing something wrong. For example, if you process a template multiple times in a loop, there is a special option for it that does it with better performance! You have something like this:

<% @followers.each do |follower| %>
  <%= render :partial => "follower", :locals => {:follower => follower}  %>
<% end %>

      

This can be done with the: collection option:



<%= render :partial => "follower", :collection => @followers %>

      

And it's more readable and more efficient. Full log output will help you debug.

0


source







All Articles