Class: EricWeixin::ApplicationController
- Inherits:
-
ActionController::Base
- Object
- ActionController::Base
- EricWeixin::ApplicationController
- Defined in:
- app/controllers/eric_weixin/application_controller.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#dispose_exception(e, error_messages = {:unknow_error=>nil, :act=>nil}) ⇒ Object
处理控制器中的异常信息。.
- #get_ip ⇒ Object
- #get_notice ⇒ Object
- #get_notice_hash ⇒ Object
- #get_notice_str(is_all = true) ⇒ Object
- #get_session_content(id) ⇒ Object
- #set_notice(str) ⇒ Object
- #set_session_content ⇒ Object
Instance Method Details
#dispose_exception(e, error_messages = {:unknow_error=>nil, :act=>nil}) ⇒ Object
处理控制器中的异常信息。
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/controllers/eric_weixin/application_controller.rb', line 9 def dispose_exception e, ={:unknow_error=>nil, :act=>nil} case e when BusinessException set_notice e.to_s return when ActiveRecord::RecordInvalid #对于模型中的字段校验,则返回一个hash,分别是字段所对应的错误信息。 errors = {} e.record.errors.each do |k, v| k = k.to_s errors[k] = v end set_notice errors errors.to_logger '.............hash'.to_logger return when ActiveRecord::RecordNotFound set_notice '记录未被找到' e.to_s.to_logger $@.to_logger return else e.to_s.to_logger $@.to_logger ExceptionNotifier.notify_exception(e) raise e set_notice [:unknow_error]||'发生未知错误' return end end |
#get_ip ⇒ Object
98 99 100 101 |
# File 'app/controllers/eric_weixin/application_controller.rb', line 98 def get_ip ip = request.env["HTTP_X_FORWARDED_FOR"]||"127.0.0.1" ip = begin ip.split(',')[0] rescue "127.0.0.1" end end |
#get_notice ⇒ Object
43 44 45 46 47 |
# File 'app/controllers/eric_weixin/application_controller.rb', line 43 def get_notice str = session[:notice] session[:notice] = nil str end |
#get_notice_hash ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'app/controllers/eric_weixin/application_controller.rb', line 67 def get_notice_hash if session[:notice].class == Hash str = session[:notice] session[:notice] = nil str else Hash.new('') end end |
#get_notice_str(is_all = true) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/controllers/eric_weixin/application_controller.rb', line 50 def get_notice_str is_all=true if session[:notice].class == String str = session[:notice] session[:notice] = nil str end if is_all return str if not str.blank? h = get_notice_hash if h.values.length>0 return h.values[0] end else return str end end |
#get_session_content(id) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'app/controllers/eric_weixin/application_controller.rb', line 85 def get_session_content id return {} if id.blank? begin s = SessionContent.where(id: id, is_valid: true).first return {} if s.blank? s.update_attribute :is_valid, false value = eval(s.value) value.deep_symbolize_keys rescue Exception => e {} end end |
#set_notice(str) ⇒ Object
39 40 41 |
# File 'app/controllers/eric_weixin/application_controller.rb', line 39 def set_notice str session[:notice] = str end |
#set_session_content ⇒ Object
79 80 81 82 83 |
# File 'app/controllers/eric_weixin/application_controller.rb', line 79 def set_session_content s = SessionContent.new(value: params.symbolize_keys.delete_if { |key, value| [:utf8, :authenticity_token].include? key }.to_s) s.save! s.id end |