Module: Edgar::ControllerMixinForApp

Defined in:
app/controllers/edgar/controller_mixin_for_app.rb

Overview

Mixin for All controllers (not only EdgarController derived classes)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Object) included(klass)



4
5
6
# File 'app/controllers/edgar/controller_mixin_for_app.rb', line 4

def self.included(klass)
  klass.helper_method :v
end

Instance Method Details

- (Object) app_rescue (private)

application-wide rescue to log error info.



28
29
30
31
32
33
34
35
# File 'app/controllers/edgar/controller_mixin_for_app.rb', line 28

def app_rescue
  logger.error(sprintf("error %s(%s) at %s#%s:\n%s",
     $!.class.to_s,
     $!.to_s,
     self.class.name,
     self.action_name,
     $@.join("\n")))
end

- (Object) human_name (private)

Transform the controller name into a more humane format, using I18n. I18n fallbacks work as follows (LeadsController as example):

  1. t('activerecord.models.lead')

  2. t('controller.leads')

  3. t('lead')

  4. 'Lead'



16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/edgar/controller_mixin_for_app.rb', line 16

def human_name
  @human_name ||= begin
    str = controller_path
    single = str.singularize
    I18n.t(         "activerecord.models.#{model_class.to_s.underscore}",
      default:      I18n.t("controller.#{str}",
        default:    I18n.t(single,
          default:  single.camelize)))
  end
end

- (Object) intern_sssn (private)

set @sssn if not exist



38
39
40
41
42
43
# File 'app/controllers/edgar/controller_mixin_for_app.rb', line 38

def intern_sssn
  # Following forces to load of the session in rails 2.3.x lazy load;-( ...
  # See http://stackoverflow.com/questions/1035933/rails-2-3-session
  session[:session_id]
  @sssn ||= Edgar::Sssn.find_by_session_id(request.session_options[:id])
end

- (Object) v(key) (private)

convenient t() for view. v(KEY) fallback works as follows:

  1. t('view.CONTROLLER.KEY') if exists. Where, CONTROLLER is controller name.

  2. t('edgar.view.CONTROLLER.KEY') if exists.

  3. t('KEY')

  4. Key



53
54
55
56
57
58
59
60
# File 'app/controllers/edgar/controller_mixin_for_app.rb', line 53

def v(key)
  t(key,
    scope:    "view.#{controller_name}",
    default:  I18n.t(key,
      scope:    "edgar.view.#{controller_name}",
      default:  I18n.t(key,
        default:  key.camelize)))
end