Class ApplicationController
In: app/controllers/application.rb
Parent: ActionController::Base

Filters added to this controller apply to all controllers in the application. Likewise, all the methods added will be available for all controllers.

Methods

Included Modules

I18n

Public Instance methods

[Source]

    # File app/controllers/application.rb, line 67
67:   def current_user
68:       session && session[:user_id] ? User.find_by_id(session[:user_id]) : nil
69:   end

[Source]

    # File app/controllers/application.rb, line 63
63:   def is_authorized_as? role
64:     return Authorize.is_role_allowed_for_user?(current_user, role)
65:   end

[Source]

    # File app/controllers/application.rb, line 50
50:   def set_defaults
51:     ActiveScaffold.set_defaults do |config| 
52:       config.ignore_columns.add [:created_at, :updated_at, :lock_version]
53:       config.show.link.label   = 'activescaffold.show'
54:       config.update.link.label = 'activescaffold.edit'
55:       config.delete.link.label = 'activescaffold.delete'
56:       config.search.link.label = 'activescaffold.search'
57:       config.create.link.label = 'activescaffold.create'
58:       config.security.current_user_method = :current_user
59:       config.security.default_permission  = false
60:     end
61:   end

[Source]

    # File app/controllers/application.rb, line 37
37:   def set_locale
38:     preferred_local = params[:user]                                               ? params[:user][:language_native]              : params[:lang] 
39:     preferred_local = preferred_local.nil? && session                             ? session[:language_native]                    : preferred_local
40:     preferred_local = preferred_local.nil? && session                             ? session[:locale]                             : preferred_local
41:     preferred_local = preferred_local.nil? && request.env["HTTP_ACCEPT_LANGUAGE"] ? request.env["HTTP_ACCEPT_LANGUAGE"].downcase : preferred_local
42:     I18n.locale     = @@LOCAL_MAP[preferred_local] || 'en'
43:     for file in Dir[ File.join(RAILS_ROOT, 'config', 'locale', '*.{rb,yml}') ]
44:       I18n.load_path << file unless I18n.load_path.include?(file)
45:     end
46:     I18n.reload!
47:     session[:locale] = I18n.locale
48:   end

[Source]

    # File app/controllers/application.rb, line 71
71:   def t(phrase)
72:     I18n.t(phrase)
73:   end

Protected Instance methods

[Source]

     # File app/controllers/application.rb, line 102
102:   def authorize
103:     @user                     = current_user
104:     unless @user
105:       flash[:notice]          = I18n.t('messages.account.please_login')
106:       session[:original_url]  = request.request_uri
107:       default_redirect_to
108:     end
109:   end

[Source]

     # File app/controllers/application.rb, line 111
111:   def default_redirect_to
112:     redirect_to(:controller => 'accounts', :action => 'login')    
113:   end

[Source]

    # File app/controllers/application.rb, line 77
77:   def save_setting_session(paramater_symbol)
78:     parameter_value = params[paramater_symbol]
79:     if parameter_value.empty?
80:       session[paramater_symbol]   = nil
81:     else
82:       session[paramater_symbol]   = parameter_value
83:     end    
84:   end

[Source]

     # File app/controllers/application.rb, line 86
 86:   def save_setting_session_map(paramater_symbol)
 87:     unless session[paramater_symbol]
 88:       session[paramater_symbol] = Hash.new
 89:     end
 90:     parameter_value = params[paramater_symbol].to_s
 91:     if parameter_value.nil? || parameter_value.empty?
 92:       session[paramater_symbol].clear
 93:     else
 94:       if session[paramater_symbol].has_key?(parameter_value)
 95:         session[paramater_symbol].delete(parameter_value)
 96:       else
 97:         session[paramater_symbol][parameter_value]   = true
 98:       end
 99:     end    
100:   end

[Validate]