New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change language immediately after updating settings #1883
Change language immediately after updating settings #1883
Conversation
app/controllers/user_controller.rb
Outdated
@@ -126,6 +126,7 @@ def account | |||
(params[:user][:auth_provider] == current_user.auth_provider && | |||
params[:user][:auth_uid] == current_user.auth_uid) | |||
update_user(current_user, params) | |||
@title = t "user.account.title" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it not be more sensible just to move setting of the title to later in the method rather than duplicating it here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It makes much more sense - I didn't realise that the redirect_to
method didn't immediately exit the method
app/controllers/user_controller.rb
Outdated
@@ -712,6 +713,7 @@ def update_user(user, params) | |||
end | |||
|
|||
if user.save | |||
@preferred_languages = current_user.preferred_languages |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this doing? Does anything actually use that member of the controller?
Was it an early attempt to reset the cache on the model that has since been replaced with the change in the model?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was a hack, that in combination with the removed memoization in user.rb
resulted in the preferred_languages being recomputed
app/models/user.rb
Outdated
@@ -189,7 +189,7 @@ def preferred_language | |||
end | |||
|
|||
def preferred_languages | |||
@preferred_languages ||= Locale.list(languages) | |||
Locale.list(languages) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than just getting rid of the memoization maybe we should use an after_save
filter to set it to nil
so that it will be recomputed on next read?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added an after_save
method and it works much better
Makes sure that the correct locale is used immediately after updating settings.
At the moment, changing the user's preferred language on the settings page doesn't take effect immediately, and the old locale language is used on the "Your settings have been successfully updated" page.