application_controller.rb 472 B

12345678910111213141516171819202122
  1. # @author Dumitru Ursu
  2. # The main Controller of the app
  3. # Here we set the locale of the application
  4. class ApplicationController < ActionController::Base
  5. protect_from_forgery with: :exception
  6. before_action :set_locale
  7. def set_locale
  8. I18n.locale = read_user_profile || params[:locale] || I18n.default_locale
  9. end
  10. def default_url_options
  11. { locale: I18n.locale }
  12. end
  13. private
  14. def read_user_profile
  15. current_user.language if current_user
  16. end
  17. end