4

ApplicationController にエラー処理メソッドがあります。

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

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

RAILS_ROOT/app/views/errors/not_found.html.erb、私はこれを持っています:

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

しかし@exception、常にnilそこにあります。試してみましたがdebug assigns、それは常に{}です。呼び出し時に代入はコピーされませんrender :templateか? もしそうなら、どうすれば入手できますか?

私はエッジレールにいます。

4

2 に答える 2

5

それは奇妙で、その理由はわかりません。別の方法として、例外を明示的なローカルとして渡してみましたか?

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

とビュー:

<h1>Error 404: Not Found</h1>
<%= debug exception %> <!-- Note no '@' -->
于 2008-10-16T18:52:53.700 に答える
1

ActionController::Baseの API ドキュメントから、次のことを試してください:

render :template => '/errors/not_found', :status => 404, :locals => {:exception => exception}
于 2008-10-16T18:54:54.197 に答える