From 124a5db5e7d3c97fb532346cb04a420dfc362776 Mon Sep 17 00:00:00 2001 From: Joseph Dudley Date: Wed, 8 Apr 2020 11:06:58 +0100 Subject: [PATCH] Fixed back button functionality Addresses #254 We now store the previous URL if coming from a topic page and use that for the back button link. --- app/controllers/offers_controller.rb | 6 ++++++ app/views/offers/show.html.erb | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/controllers/offers_controller.rb b/app/controllers/offers_controller.rb index 3eb77ea..22abd88 100644 --- a/app/controllers/offers_controller.rb +++ b/app/controllers/offers_controller.rb @@ -12,5 +12,11 @@ def show end @offer = Offer.find(params[:id]) + + previous_url = URI(request.referer || '').path + if previous_url.include? "topic" + session[:previous_url] = previous_url + end + @back_url = session[:previous_url] end end diff --git a/app/views/offers/show.html.erb b/app/views/offers/show.html.erb index 5feb441..d6d1e57 100644 --- a/app/views/offers/show.html.erb +++ b/app/views/offers/show.html.erb @@ -1,7 +1,7 @@ <%= render partial: 'projects/subnav' %>
-

<%= link_to '‹ Back', :back, class: 'underline' %>

+

<%= link_to '‹ Back', @back_url, class: 'underline' %>

<%= render partial: 'layouts/notices' %>