Class: Anoubis::ApplicationController
- Inherits:
-
ActionController::API
- Object
- ActionController::API
- Anoubis::ApplicationController
- Includes:
- ActionController::Cookies
- Defined in:
- app/controllers/anoubis/application_controller.rb
Overview
Main application controller class inherited from ActionController::API
Instance Attribute Summary collapse
-
#locale ⇒ Object
Current used locale.
-
#redis ⇒ Class
Returns Redis database class.
-
#redis_prefix ⇒ String
Returns Redis prefix for storing cache data.
Instance Method Summary collapse
-
#check_origin ⇒ Boolean
Check current origin of header.
-
#default_locale ⇒ String
Returns default locale initialized in application configuration file.
-
#options(methods = 'POST') ⇒ Object
Generates options headers for CORS requests.
-
#pba_anoubis_application ⇒ Object
Procedure fires before any action and setup default variables.
Instance Attribute Details
#locale ⇒ Object
Current used locale
11 12 13 |
# File 'app/controllers/anoubis/application_controller.rb', line 11 def locale @locale end |
#redis ⇒ Class
Returns Redis database class
8 9 10 |
# File 'app/controllers/anoubis/application_controller.rb', line 8 def redis @redis end |
#redis_prefix ⇒ String
Returns Redis prefix for storing cache data. Prefix can be set in Rails.configuration.anoubis_redis_prefix configuration parameter.
21 22 23 |
# File 'app/controllers/anoubis/application_controller.rb', line 21 def redis_prefix @redis_prefix end |
Instance Method Details
#check_origin ⇒ Boolean
Check current origin of header. By default origin always valid
75 76 77 |
# File 'app/controllers/anoubis/application_controller.rb', line 75 def check_origin true end |
#default_locale ⇒ String
Returns default locale initialized in application configuration file. Variable is taken from Rails.configuration.i18n.default_locale parameter
16 17 18 |
# File 'app/controllers/anoubis/application_controller.rb', line 16 def default_locale Rails.configuration.i18n.default_locale.to_s end |
#options(methods = 'POST') ⇒ Object
Generates options headers for CORS requests
63 64 65 66 67 68 69 70 |
# File 'app/controllers/anoubis/application_controller.rb', line 63 def (methods = 'POST') if check_origin headers['Access-Control-Allow-Origin'] = request.headers['origin'] headers['Access-Control-Allow-Methods'] = methods headers['Access-Control-Max-Age'] = '1000' headers['Access-Control-Allow-Headers'] = '*,x-requested-with,Content-Type,Authorization' end end |
#pba_anoubis_application ⇒ Object
Procedure fires before any action and setup default variables.
49 50 51 52 53 54 55 56 57 58 |
# File 'app/controllers/anoubis/application_controller.rb', line 49 def pba_anoubis_application self.locale = params[:locale] if params.has_key? :locale self.locale = default_locale unless self.locale self.locale = default_locale if self.locale == '' begin I18n.locale = locale rescue I18n.locale = default_locale end end |