加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 如何在“render:template => …”之后访问

发布时间:2020-12-17 02:57:31 所属栏目:百科 来源:网络整理
导读:我的ApplicationController中有一个错误处理方法: rescue_from ActiveRecord::RecordNotFound,:with = :not_founddef not_found(exception) @exception = exception render :template = '/errors/not_found',:status = 404end 在RAILS_ROOT / app / views /
我的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总是没有.我已经尝试过调试分配,但这总是{}.调用render:template时不会复制分配吗?如果是这样,我怎么能得到它们?

我在边缘Rails.

解决方法

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

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 '@' -->

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读