rails2.3.2 ExceptionNotifier 配置
必须先在项目中要加入plugin
然后
首先在development.rb文件中加入
Ruby代码- ActionMailer::Base.delivery_method = :smtp
- ActionMailer::Base.smtp_settings = {
- :address => "smtp.a-it.jp",
- :domain => "smtp.a-it.jp",
- :port => 25,
- :authentication => :login,
- :user_name => "rails",
- :password => "rails",
- }
- ActionMailer::Base.delivery_method = :smtp
- ActionMailer::Base.smtp_settings = {
- :address => "smtp.a-it.jp",
- :domain => "smtp.a-it.jp",
- :port => 25,
- :authentication => :login,
- :user_name => "rails",
- :password => "rails",
- } 然后在environment.rb中加入
复制代码 Ruby代码- ActionView::Base.field_error_proc = Proc.new {|html_tag, instance|
- %(<span class="field-with-errors">#{html_tag}</span>)}
- #ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.update( :default => '%Y-%m-%d %H:%M:%S' )
- #邮件发送地址
- ExceptionNotifier.sender_address = %("Application Error<error_sender>)
- #邮件前缀
- ExceptionNotifier.email_prefix = "[email title]"
- #邮件接收者
- ExceptionNotifier.exception_recipients = %w(youremails)
- ActionView::Base.field_error_proc = Proc.new {|html_tag, instance|
- %(<span class="field-with-errors">#{html_tag}</span>)}
- #ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.update( :default => '%Y-%m-%d %H:%M:%S' )
- #邮件发送地址
- ExceptionNotifier.sender_address = %("Application Error<error_sender>)
- #邮件前缀
- ExceptionNotifier.email_prefix = "[email title]"
- #邮件接收者
- ExceptionNotifier.exception_recipients = %w(youremails)
- 再在application_controller.rb中加入
复制代码 Ruby代码- rescue_from Exception do |exception|
- pp exception
- case exception
- when "ActionController::NameError"
- flash[:error] = exception.message.to_s
- when "ActiveRecord::RecordNotFound"
- flash[:error] = exception.message.to_s
- when "ActionController::UnknownAction"
- flash[:error] = exception.message.to_s.split(".")[0] rescue "No action responded to #{params[:action]}"
- else
- return rescue_action_in_public(exception)
- end
- redirect_to :controller => 'blog', :action => "list"
- end
- rescue_from Exception do |exception|
- pp exception
- case exception
- when "ActionController::NameError"
- flash[:error] = exception.message.to_s
- when "ActiveRecord::RecordNotFound"
- flash[:error] = exception.message.to_s
- when "ActionController::UnknownAction"
- flash[:error] = exception.message.to_s.split(".")[0] rescue "No action responded to #{params[:action]}"
- else
- return rescue_action_in_public(exception)
- end
- redirect_to :controller => 'blog', :action => "list"
复制代码 end 哈哈,这样就大功告成了!!!
|