Redirect to referer from preferences

This commit is contained in:
Anton Khorev
2025-06-18 15:51:33 +03:00
parent b989922b2b
commit f31d53bea8
2 changed files with 9 additions and 2 deletions

View File

@ -15,8 +15,9 @@ module Preferences
def update
if update_preferences
# Use a partial so that it is rendered during the next page load in the correct language.
flash[:notice] = { :partial => "update_success_flash" }
redirect_to :action => :show
flash[:notice] = { :partial => "preferences/preferences/update_success_flash" }
referer = safe_referer(params[:referer]) if params[:referer]
redirect_to referer || { :action => :show }
else
flash.now[:error] = t "failure", :scope => "preferences.preferences.update"
render :show

View File

@ -61,6 +61,12 @@ module Preferences
assert_equal "light", user.preferences.find_by(:k => "map.color_scheme")&.v
end
def test_update_with_referer
session_for(create(:user))
put basic_preferences_path, :params => { :referer => root_path }
assert_redirected_to root_path
end
def test_update_preferred_language_from_en_selecting_fr
check_language_change %w[en], "fr", %w[fr]
end