Skip to content
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

Conversation

jguthrie100
Copy link
Contributor

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.

@@ -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"
Copy link
Member

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?

Copy link
Contributor Author

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

@@ -712,6 +713,7 @@ def update_user(user, params)
end

if user.save
@preferred_languages = current_user.preferred_languages
Copy link
Member

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?

Copy link
Contributor Author

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

@@ -189,7 +189,7 @@ def preferred_language
end

def preferred_languages
@preferred_languages ||= Locale.list(languages)
Locale.list(languages)
Copy link
Member

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?

Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants