如何在"render:template => ..."之后访问"assign"?

Jam*_*sen 4 ruby ruby-on-rails actionview

我的ApplicationController中有一个错误处理方法:

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

def not_found(exception)
  @exception = exception
  render :template => '/errors/not_found', :status => 404
end
Run Code Online (Sandbox Code Playgroud)

RAILS_ROOT/app/views/errors/not_found.html.erb,我有这个:

<h1>Error 404: Not Found</h1>
<%= debug @exception %>
Run Code Online (Sandbox Code Playgroud)

@exception总是nil在那里.我试过了debug assigns,但总是这样{}.打电话时不会复制分配render :template吗?如果是这样,我怎么能得到它们?

我在边缘Rails.

Avd*_*vdi 5

这很奇怪,我不知道为什么.作为替代方案,您是否尝试将异常作为显式本地传递?

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

和观点:

<h1>Error 404: Not Found</h1>
<%= debug exception %> <!-- Note no '@' -->
Run Code Online (Sandbox Code Playgroud)