浏览 190 次
|
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
|---|---|
| 作者 | 正文 |
|
时间:2008-05-09
就是在action中,当传入的ID通过 model.find(params[:id])没找到时,比如用户手动输入的id。就会出现难看的ActiveRecord::RecordNotFound页面。
我现在的做法是在ApplicationController加了
around_filter :rescue_record_not_found
def rescue_record_not_found
begin
yield
rescue ActiveRecord::RecordNotFound
render :file => "#{RAILS_ROOT}/public/404.html"
end
end
一般来说应该怎么处理这个问题? 声明:JavaEye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
| 返回顶楼 | |
|
时间:2008-05-09
|
|
| 返回顶楼 | |
|
时间:2008-05-10
改成
rescue_from ActiveRecord::RecordNotFound :with => :rescue_record_not_found
def rescue_record_not_found
render :file => "#{RAILS_ROOT}/public/404.html"
end
很好用。谢谢~~ |
|
| 返回顶楼 | |
|
时间:昨天
如果有新的异常,可以在用rescue_from ActiveRecord::RecordNotFound :with => :rescue_record_not_found 不会覆盖把?
可以继续添加吗? 例如: rescue_from Mysql::Error :with => :rescue_mysql_error def rescue_mysql_error render :file => "#{RAILS_ROOT}/public/404.html" end 这样可以吗?如果数据库突然关闭,或者连接不上,该怎么捕获此类异常 |
|
| 返回顶楼 | |




