I set the locale for every user in the User table. I followed these instructions to fetch the locale after the user logs in. It works until the user reloads the browser, then the standard locale (en) becomes active again. How can I keep the value of user.locale in the session? I’m using Rails_Admin, which means whilst I do have a User model, I don’t have controller for the User model.
# ApplicationController
def after_sign_in_path_for(resource_or_scope)
if resource_or_scope.is_a?(User) && resource_or_scope.locale != I18n.locale
I18n.locale = resource_or_scope.locale
end
super
end
While putting it in the session is a valid answer, you can use the
current_usermethod to get the user’s locale (and keep your session a tad cleaner)