adopt-a-hydrant/app/controllers/application_controller.rb

23 lines
680 B
Ruby
Raw Permalink Normal View History

2011-02-14 18:28:51 +00:00
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
2014-03-25 09:47:44 +00:00
protect_from_forgery with: :exception
2014-04-01 08:15:29 +00:00
before_action :set_flash_from_params
before_action :set_locale
2011-08-30 00:50:51 +00:00
protected
def set_flash_from_params
2014-05-22 11:03:34 +00:00
params.fetch(:flash, []).each do |key, message|
flash.now[key.to_sym] = message
2011-08-30 00:50:51 +00:00
end
end
def set_locale
2014-04-01 08:15:29 +00:00
available_languages = Dir.glob(Rails.root + 'config/locales/??.yml').collect do |file|
File.basename(file, '.yml')
end
I18n.locale = http_accept_language.compatible_language_from(available_languages) || I18n.default_locale
end
2011-02-14 18:28:51 +00:00
end