title: accessing variables in rescue_from block
body: <p>So I have a fairly common rescue_from block in a Rails app:</p>
  
  <pre><code>  if Rails.env.production?
      unless Rails.application.config.consider_all_requests_local
        rescue_from Exception, with: lambda { |exception| render_error 500, exception }
        rescue_from Mongoid::Errors::DocumentNotFound, with: lambda { |exception| render_error 404, exception }
      end
    end
  </code></pre>
  
  <p>but I want to be able to see the error message if I'm an admin user, so I change the "unless" line to:</p>
  
  <pre><code>    unless Rails.application.config.consider_all_requests_local || (current_user.present? &amp;&amp; current_user.site_amdin)
  </code></pre>
  
  <p>but rails complains: "undefined local variable or method `current_user' for ApplicationController:Class"</p>
  
  <p>So how can I access the instance variables, since the code isn't within a block?</p>
  
  <p>I also tried to wrap it in the before_filter block:</p>
  
  <pre><code>before_filter do
   if Rails.env.production? || (current_user.present? &amp;&amp; current_user.site_admin)
      unless Rails.application.config.consider_all_requests_local
        Application.rescue_from Exception, with: lambda { |exception| render_error 500, exception }
        Application.rescue_from Mongoid::Errors::DocumentNotFound, with: lambda { |exception| render_error 404, exception }
      end
   end
  </code></pre>
  
  <p>end</p>
  
  <p>but the app wouldn't run on the server.</p>