Class: ApplicationController

Inherits:
ActionController::Base
  • Object
show all
Includes:
Authentication
Defined in:
app/controllers/application_controller.rb

Instance Method Summary collapse

Instance Method Details

#dispatch(name, request) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/application_controller.rb', line 18

def dispatch(name, request)
  begin 
    super
  rescue Sequel::DatabaseConnectionError => e
    response.status = 500
    response.body = 'Database connection faild.'
  rescue ActiveResource::ConnectionError => e 
    if is_dcmgr?(e)
      response.status = e.response.code 
      response.body = e.response.body
      response['X-Vdc-Request-Id'] = e.response['X-Vdc-Request-Id']  
    else
      raise
    end
  end
  to_a
end

#get_localesObject



64
65
66
67
68
69
# File 'app/controllers/application_controller.rb', line 64

def get_locales
  locales = Array.new
  locales.push(['English','en'])
  locales.push(['日本語','ja'])
  locales
end

#is_dcmgr?(response_data) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
39
40
41
42
# File 'app/controllers/application_controller.rb', line 36

def is_dcmgr?(response_data)
  if response_data.response['X-Vdc-Request-Id']
    true
  else
    false
  end
end

#set_applicationObject



13
14
15
16
# File 'app/controllers/application_controller.rb', line 13

def set_application
  @site = DCMGR_GUI_SITE
  true
end

#set_localeObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/controllers/application_controller.rb', line 44

def set_locale
  language = params[:select_language] if params[:select_language]
  if language
    I18n.locale = language[:locale]
    session[:locale] = I18n.locale
  else
    if session[:locale]
      I18n.locale = session[:locale]
    elsif @current_user
      I18n.locale = @current_user.locale
    else
      I18n.locale = I18n.default_locale.to_s
    end
  end
  
  @locales = get_locales 
  @locale = I18n.locale
  true
end