blob: cbeb40dbb8505f729a52f24885ea84728ae38e9a (
plain)
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
|
class ApplicationController < ActionController::Base
include AuthenticatedSystem
protect_from_forgery
before_action :set_locale
helper_method :safe_return_to
protected
def set_locale
if params[:locale] && I18n.available_locales.include?(params[:locale].to_sym)
I18n.locale = params[:locale].to_sym
else
I18n.locale = I18n.default_locale
end
end
def default_url_options
{ locale: I18n.locale == I18n.default_locale ? nil : I18n.locale }
end
def safe_return_to(url)
return events_path if url.blank?
uri = URI.parse(url)
return events_path if uri.host.present?
return events_path unless url.start_with?('/')
url
rescue URI::InvalidURIError
events_path
end
end
|