diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 43b865b4..98b12446 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -10,6 +10,8 @@ class ApplicationController < ActionController::Base before_action :set_locale before_action :configure_permitted_parameters, if: :devise_controller? + before_action :save_return_to_path, + if: ->(c) { c.controller_name == 'sessions' && c.action_name == 'new' } def authenticate_user! redirect_to(new_auth_user_session_path) unless user_signed_in? @@ -79,5 +81,24 @@ class ApplicationController < ActionController::Base devise_parameter_sanitizer.permit(:sign_up, keys: [:email]) devise_parameter_sanitizer.permit(:account_update, keys: [:email]) end + + def save_return_to_path + if params[:return_to] + Rails.logger.debug "Saving return_to path: #{params[:return_to].inspect}" + session[:devise_return_to] = params[:return_to] + end + end + + def after_sign_in_path_for(user) + return_to = session.delete(:devise_return_to) + Rails.logger.debug "Using return_to path: #{return_to.inspect}" + return_to || root_path + end + + def after_sign_out_path_for(user) + return_to = params[:return_to] + Rails.logger.debug "Using return_to path: #{return_to.inspect}" + return_to || root_path + end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 60c134a6..69bcf616 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -156,10 +156,6 @@ module ApplicationHelper end.html_safe end end - - def return_to_field_tag - hidden_field_tag :return_to, request.fullpath - end def safely_to_json(obj) obj.to_json.gsub('/', '\/') diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 7155b8d3..e8a5f796 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -48,7 +48,8 @@ = link_to t('.userbar.items'), user_closet_hangers_path(current_user), :id => 'userbar-items-link' = link_to t('.userbar.outfits'), current_user_outfits_path = link_to t('.userbar.settings'), edit_auth_user_registration_path - = button_to t('.userbar.logout'), destroy_auth_user_session_path, method: :delete + = button_to t('.userbar.logout'), destroy_auth_user_session_path, method: :delete, + params: {return_to: request.fullpath} - else = link_to auth_user_sign_in_path_with_return_to, :id => 'userbar-log-in' do %span= t('.userbar.login')