Module: Lesli::Interfaces::Application::Requester
- Included in:
- ApplicationDeviseController, ApplicationLesliController
- Defined in:
- app/controllers/lesli/interfaces/application/requester.rb
Instance Method Summary collapse
-
#set_locale ⇒ Object
Set the user language based on user_settings, session configuration or instance default locale.
- #set_path ⇒ Object
-
#set_requester ⇒ Object
Set default query params for:.
Instance Method Details
#set_locale ⇒ Object
Set the user language based on user_settings, session configuration or instance default locale
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/controllers/lesli/interfaces/application/requester.rb', line 43 def set_locale # get saved language in session, browser language or the default in config # the session param is setted in settings controller through "get :language, to: "settings#language"" locale = session[:locale] || I18n.default_locale # get user's preferred language # IMPORTANT: # Here it's not possible to use the methods provided by devise to check if user is # authenticated "user_signed_in", due those methods redirects to the login controller # if user is not authenticated; For some scenarios we need to have control of the behavior # for not authenticated user requests, thats why here we go deeper and check if user is # authenticated checking the warden storage # locale = current_user.locale if warden.authenticated? # language defined in the http header request locale = request.headers["Require-Language"] unless request.headers["Require-Language"].blank? # use default locale if requested language is not supported locale = I18n.default_locale unless I18n.available_locales.include?(locale.to_sym) # set the new locale I18n.locale = locale end |
#set_path ⇒ Object
38 39 40 |
# File 'app/controllers/lesli/interfaces/application/requester.rb', line 38 def set_path @@engine_path = Lesli::Engine.routes.find_script_name({}) end |
#set_requester ⇒ Object
Set default query params for:
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/controllers/lesli/interfaces/application/requester.rb', line 68 def set_requester @query = { search: params[:search] || nil, pagination: { perPage: (params[:perPage] ? params[:perPage].to_i : 12), page: (params[:page] ? params[:page].to_i : 1) }, order: { by: (params[:orderBy] || "id"), dir: (params[:order] || "desc") } } end |