AD

Rails3 custom error page by rescue_from

Before long my custom error pages are rewritten Showexceptions the rescue_action_in_public and rescue_action_locally methods, but this is too invasive, and today when I see a method: rescue_from approach, using as follows;
rescue_from (* klasses, & block)
Its first argument is the wrong type of collection, you can specify multiple types of errors or error messages, each one will call klass.is_a? (Klass); second parameter is with a block, we can use to specify with :
Error handling can be inherited, such as under the code, if not specified the type of error handling, they would transfer the same rescue_from 'MyAppError:: Base' error handling;
class ApplicationController < ActionController::Base
rescue_from ActiveRecord::InvalidForeignKey,ActiveRecord::StatementInvalid , :with => :show_fk_errors

    rescue_from 'MyAppError::Base' do |exception|
      render :xml => exception, :status => 500
    end

  protected

  def show_fk_errors(exception)
    render :template => "/errors/fk_error.html.erb",:object=>@exception = exception
  end
end


PS:
Ruby file in the wrong if there are Chinese, then you can add in the beginning of the file
#encoding: utf-8
。。。。。。

To specify the file encoding, if it is an error code if you manually turn it. . .
标签: lt, amp, utf 8, error messages, klass, exception status, custom error, ps ruby
分类: Ruby
时间: 2011-01-04

相关文章

  1. jsp custom error page

    To give visitors a friendly error page, as we can as IIS custom error page; As follows: First, open the WEB-IN ...
  2. [Transfer] with anti-hotlinking Apache custom error page set up and

    Anti-hotlinking settings and the Apache custom error page This article is reproduced http://www.discuz.net/thr ...
  3. (Transfer) web.xml configuration 404 and 500 custom error page

    web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.4" x ...
  4. Custom error page, and catch the exception to the database

    web.xml adding this section to deal with 404 other state information, note the error-code <error-page> & ...
  5. Catch 404/500 error, custom Tomcat error page

    When the server error occurs 404,500 times want to give user-friendly interface, just the reality of the proje ...
  6. Rails 3 custom error message displayed next page

    We all know that Rails would like displayed under a custom error page is modified rescue_action_in_public this ...
  7. How to customize the Tomcat 404 error page

    In the Tomcat installation directory conf / web.xml final </ web-app> before adding the following code: ...
  8. Error Page can not be transmitted in the issue under IE

    Error Page can not be transmitted in the issue under IE This is due to IE's own set, after Baidu, find a few s ...
  9. apache 404 error page of description of the custom Jump

    404 In fact, we often see is that the error can not find the file, but that is the default effect, it is diffi ...
  10. Django in the 404/500 error page

    If DEBUG is set in settings.py True, when the exception occurs within the system, django will be the default e ...
  11. How to properly set up Apache 404 error page: 404 error code and the relationship between seo

    How to properly set up Apache 404 error page: 404 error code and the relationship between seo Apache Server se ...
  12. Amendment CuteEditor error "page using the theme css file requests have the header file"

    CuteEditor function is very powerful and easy to use, the project prefer to use it, but depressing it is used ...
  13. Custom error reporting

    / * Custom error reporting program trigger the occurrence of trigger_error set_error_handler defines the param ...
  14. Jump solutions error page

    Jump solutions error page Configuring error pages in web.xml Jump as follows: <error-page> <exception ...
  15. web.xml error page configuration 404,500

    <! - 400 error -> <error-page> <error-code> 400 </ error-code> <location> / erro ...
  16. Cakephp custom query page problems, solutions

    Reprinted Cakephp custom query page the problem, the solution collection Cakephp default paging function is as ...
  17. (Switch) on the JSP error page handling

    Usually in the implementation of JSP, in two stages under an error. JSP page → Servlet class Servlet class han ...
  18. 15 very creative 404 error page

    Three Weeks ago we've showcased some of the most Beautiful, Creative and User-Friendly 404 Error Pages ; we've ...
  19. Found a Google error page

    Google selection to find the software at night, suddenly found there was a error page, we appreciate it.