I'm having a challenge tracking down a fix for the following:
I am able to login/logout in my development environment
I am unable to logout in my production environment
I've looked at and tried solutions to the following questions:
- How to destroy a session in Rails
- Set session to nil manually instead of using sorcery's #logout
- Changing the HTTP methods from DELETE to GET
- config.serve_static_assets & rails_12factor gem
- Heroku not recognizing a cookie for User.first
I notice SQL in heroku logs is saying Select employees where deleted_at is null, otherwise just seeing a GET request to sessions#new as I click 'logout'.
Here is my code:
sessions_controller.rb
class SessionsController < ApplicationController
skip_before_action :require_login, except: [:destroy]
def new
@employee = Employee.new
end
def create
if @employee = login(params[:email], params[:password])
flash[:success] = "You're logged in!"
redirect_back_or_to(root_path)
else
@employee = Employee.new
flash.now[:notice] = "Login failed."
render :new
end
end
def destroy
logout
flash.now[:notice] = "You have successfully logged out."
redirect_to(root_path)
end
end
_nav.html.erb
<li>
<% if current_employee.present? %>
<% if current_employee.is_admin %>
<h5 style="margin-top: 5%;">
Logged in as <strong><em><%= current_employee.email %></em></strong>
<%= link_to('Edit Account', edit_account_path(current_employee.account_id), class: "text-normal") %>
- or -
<%= link_to('Logout', logout_path, options = { method: :delete, class: "text-normal" }) %>
</h5>
<% elsif current_employee.is_admin == false %>
<h5 style="margin-top: 5%;">
Logged in as <strong><em><%= current_employee.email %></em></strong>
<%= link_to('Edit Profile', edit_employee_path(current_employee), class: "text-normal") %>
- or -
<%= link_to('Logout', logout_path, options = { method: :delete, class: 'text-normal' }) %>
</h5>
<% end %>
<% else %>
<h5 style="margin-top: 9.5%;">
|
<%= link_to('Login', login_path, id: "employee_login", class: "text-normal") %>
- or -
<%= link_to('Register Today!', new_account_path, id:"admin_registration", class: "text-normal") %>
</h5>
<% end %>
</li>
routes.rb
Rails.application.routes.draw do
root to: "static_pages#home"
get "static_pages/about", to: "static_pages#about", as: :about
get "static_pages/pricing", to: "static_pages#pricing", as: :pricing
get "static_pages/contact", to: "static_pages#contact", as: :contact
get "sessions", to: "sessions#new", as: :login
post "sessions", to: "sessions#create"
delete "sessions", to: "sessions#destroy", as: :logout
resources :employees
end
config/production.rb (Added these configs)
Rails.application.configure do
config.cache_classes = true
config.assets.compile = true
config.assets.digest = true
end
Thanks in advance for volunteering a fresh set of eyes!