-
Notifications
You must be signed in to change notification settings - Fork 105
Expand file tree
/
Copy pathapplication_controller.rb
More file actions
47 lines (35 loc) · 1.25 KB
/
application_controller.rb
File metadata and controls
47 lines (35 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# frozen_string_literal: true
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
rescue_from CanCan::AccessDenied do |_exception|
redirect_to root_path, alert: I18n.t('errors.access_denied')
end
before_action :load_locale
private
def load_locale
locale = locale_from_params || session[:locale] || locale_from_http_accept_language
I18n.locale = session[:locale] = locale
redirect_back(fallback_location: root_path) if params[:locale].present?
end
def locale_from_params
return unless params[:locale]
return unless ::Rails.application.config.available_locales.include?(params[:locale])
params[:locale].to_sym
end
def locale_from_http_accept_language
http_accept_language.compatible_language_from(::Rails.application.config.available_locales)&.to_sym
end
def pretty_project_path?
params[:service].present? && params[:repo].present?
end
def project_not_found
flash[:error] = I18n.t('errors.project_not_found')
redirect_to(projects_path)
end
def user_not_found
flash[:error] = I18n.t('errors.user_not_found')
redirect_to(users_path)
end
end