Class: ApplicationController

Inherits:
ActionController::Base
  • Object
show all
Includes:
ActionController::MimeResponds, ControllerHelpers, ElasticApmContext, LogrageCustomLogger
Defined in:
app/controllers/application_controller.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from LogrageCustomLogger

#append_info_to_payload

Methods included from ControllerHelpers

#check_boolean_param, #get_banners, #inventory_params, #reservation_params

Class Method Details

.search_params_key=(search_key) ⇒ Object

Data Grid search parameters



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'app/controllers/application_controller.rb', line 109

def self.search_params_key=(search_key)
  define_method :search_params do
    return nil if search_key.nil?
    return {} if params[search_key].blank?

    params.permit![search_key].select do |_key, value|
      if value.is_a?(Array)
        result = false
        value.each do |val|
          result = true if val.present?
        end
        result
      else
        value.present?
      end
    end
  end
end

Instance Method Details

#after_sign_in_path_for(_resource) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/application_controller.rb', line 19

def (_resource)
  if session[:redirect_to].present?
    path = session[:redirect_to]
    session[:redirect_to] = nil
    return path
  end
  return owner_dashboards_path if owner_signed_in?
  return root_path if user_signed_in?

  root_path
end

#after_sign_out_path_forObject



31
32
33
# File 'app/controllers/application_controller.rb', line 31

def after_sign_out_path_for(*)
  root_path
end

#default_url_optionsObject



35
36
37
# File 'app/controllers/application_controller.rb', line 35

def default_url_options
  { locale: I18n.locale }
end

#identity_cache_memoization(&block) ⇒ Object



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

def identity_cache_memoization(&block)
  IdentityCache.cache.with_memoization(&block)
end

#render_not_foundObject

Raises:

  • (ActionController::RoutingError)


80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'app/controllers/application_controller.rb', line 80

def render_not_found
  raise(ActionController::RoutingError, params[:path]) if Rails.env.development?

  query_param = request.query_parameters.to_param
  url = params[:path].to_s
  if url.include?('en-US')
    url.gsub!('en-US', 'en')
  elsif url.include?('th-TH')
    url.gsub!('th-TH', 'th')
  else
    url = "#{AdminSetting.web_v2_host}/#{url}?#{query_param}"
    redirect_to(url) && return
  end
  url = "#{Figaro.env.hh_host_url}/#{url}?#{query_param}"
  redirect_to url
  # render('/404', layout: nil, status: 404, formats: :html)
end

#routing_errorObject

Raises:

  • (ActionController::RoutingError)


41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'app/controllers/application_controller.rb', line 41

def routing_error
  raise(ActionController::RoutingError, params[:path]) if request.fullpath.include?('wp-content/uploads')

  path = params[:path].split('/').first
  landing_page_slugs = Rails.cache.fetch('landing_page_slugs', expires_in: CACHEFLOW.generate_expiry) do
    GroupLandingPage.all.map(&:friendly_id)
  end

  locale = if MyLocaleManager.available_locales.include?(params[:locale].to_s.to_sym)
             params[:locale]
           else
             I18n.default_locale
           end
  query_param = request.query_parameters.to_param
  if landing_page_slugs.include?(path)
    if Figaro.bool_env('ENABLE_WEB_NEW_UI')
      return redirect_to("#{AdminSetting.web_v2_host}/#{path}?#{query_param}")
    else
      path = "#{AdminSetting.web_v2_host}/restaurants/group/#{path}?locale=#{MyLocaleManager.normalize_locale}"
      return redirect_to path
    end
  end

  raise(ActionController::RoutingError, params[:path]) if Rails.env.development?

  url = params[:path].to_s
  if url.include?('en-US')
    url.gsub!('en-US', 'en')
  elsif url.include?('th-TH')
    url.gsub!('th-TH', 'th')
  else
    url = "#{AdminSetting.web_v2_host}/#{url}?#{query_param}"
    redirect_to(url) && return
  end
  url = "#{Figaro.env.hh_host_url}/#{url}?#{query_param}"
  redirect_to url
  # raise ActionController::RoutingError, params[:path]
end