title: Why is my Rails custom error page ignoring a custom layout?
body: <p>I have custom dynamic error pages in my Rails 3.2 app.</p>
  
  <p>To ensure that the these error pages don't themselves throw errors, they use a simplified application layout that removes, among other things, dynamic user-account information (ie. like a user avatar in the header) using a simplified layout <code>application-limited.html.erb</code>.</p>
  
  <pre><code> # config/application.rb
   config.exceptions_app = self.routes
  
   # routes.rb
   get '/404', to: 'errors#page_not_found', as: :page_not_found
  
   # errors_controller.rb
   class ErrorsController &lt; ApplicationController
     def page_not_found
       render status: 404, layout: 'application-limited'
     end
   end
  </code></pre>
  
  <p>When I test by visiting <code>/404</code> or <code>/500</code> the error page renders correctly with the limited layout. However when I test by visiting a non-existent page <code>/foobar</code> I get the correct dynamic 404 error page, but strangely the normal application layout is rendered, rather than the simplified <code>application-limited</code> layout.</p>
  
  <p><strong>What am I missing here?</strong></p>
  
  <p><em>UPDATE:</em></p>
  
  <p>Some more experimenting shows that while inheriting <code>ErrorsController</code> from <code>ActionController::Base</code> as suggested by @BoraMa <strong>does ensure</strong> that when visiting <code>/404</code> the default layout is never used, this does not carry over to visting <code>/foobarxyz</code> and rendering the custom 404 error page.</p>
  
  <p>There's obviously a reason for this, but I'm yet to work it out!?</p>