Keep GET params in return URL

When signing in from a page containing GET params, like
`/budgets/1/investments?heading_id=4`, we were redirected to a URL
without those GET params; in this case, `/budgets/1/investments`.

Using the request fullpath, as recommended in the devise documentation,
keeps these parameters when redirecting.
This commit is contained in:
Andriy Iun
2020-05-26 09:57:42 +02:00
committed by Javi Martín
parent 7a1bd06fa4
commit 1ee750e042
2 changed files with 14 additions and 1 deletions

View File

@@ -108,7 +108,7 @@ class ApplicationController < ActionController::Base
def set_return_url
if !devise_controller? && controller_name != "welcome" && is_navigational_format?
store_location_for(:user, request.path)
store_location_for(:user, request.fullpath)
end
end

View File

@@ -17,4 +17,17 @@ describe "Sessions" do
expect(page).to have_content("You have been signed out successfully")
expect(page).to have_current_path(debate_path(debate))
end
scenario "Sign in redirects keeping GET parameters" do
create(:user, :level_two, email: "dev@consul.dev", password: "consuldev")
heading = create(:budget_heading, name: "outskirts")
visit budget_investments_path(heading.budget, heading_id: "outskirts")
click_link "Sign in"
fill_in "user_login", with: "dev@consul.dev"
fill_in "user_password", with: "consuldev"
click_button "Enter"
expect(page).to have_current_path budget_investments_path(heading.budget, heading_id: "outskirts")
end
end