Module: Lesli::RequesterInterface

Included in:
ApplicationDeviseController, ApplicationLesliController
Defined in:
app/interfaces/lesli/requester_interface.rb

Instance Method Summary collapse

Instance Method Details

#set_localeObject

Set the user language based on user_settings, session configuration or instance default locale



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/interfaces/lesli/requester_interface.rb', line 37

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_requesterObject

Set default query params for:



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'app/interfaces/lesli/requester_interface.rb', line 62

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