Frage

Ich habe ein Fehlerbehandlungsverfahren in meiner Application:

rescue_from ActiveRecord::RecordNotFound, :with => :not_found

def not_found(exception)
  @exception = exception
  render :template => '/errors/not_found', :status => 404
end

In RAILS_ROOT/app/views/errors/not_found.html.erb, ich habe dies:

<h1>Error 404: Not Found</h1>
<%= debug @exception %>

Aber @exception immer da ist nil. Ich habe versucht, debug assigns, aber das ist immer {}. Sie Abtretungsempfänger nicht kopiert werden, wenn render :template Aufruf? Wenn ja, wie kann ich sie bekommen?

Ich bin auf dem Rand Rails.

War es hilfreich?

Lösung

Das ist seltsam, und ich weiß nicht, warum. Als Alternative haben Sie die Ausnahme als explizite lokale versucht vorbei?

def not_found(exception)
  render :template => '/errors/not_found', 
         :status   => 404, 
         :locals   => {:exception => exception}
end

und die Aussicht:

<h1>Error 404: Not Found</h1>
<%= debug exception %> <!-- Note no '@' -->

Andere Tipps

Von der API-Dokumentation für Action :: Base es aussieht wie sollten Sie versuchen:

render :template => '/errors/not_found', :status => 404, :locals => {:exception => exception}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top