ubuntu, ror, jQuery, css, website memo
太嫩, 沒啥心得, 用來紀錄每天學的
2010年3月9日 星期二
rescue_from Exception Handlers
rescue_from Exception Handlers
class PostsController < ApplicationController
def rescue_action_in_public(exception)
case(exception)
when ActiveRecord::RecordNotFound
render :file => '/bad_record'
when NoMethodError
render :file => '/no_method'
else
render :file => '/error'
end
end
end
#======================================
class PostsController < ApplicationController
# Declare exception to handler methods
rescue_from ActiveRecord::RecordNotFound, :with => :bad_record
rescue_from NoMethodError, :with => :show_error
# Define handler methods
def bad_record
render :file => '/bad_record'
end
def show_error(exception)
render :text => exception.message
end
end
#======================================
class PostsController < ApplicationController
rescue_from(ActiveRecord::RecordNotFound) do |exception|
render :file => '/bad_record'
end
rescue_from NoMethodError, :with => proc do |e|
render :text => e.message
end
end
沒有留言:
張貼留言
較新的文章
較舊的文章
首頁
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言