2

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:

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'.

Heroku logs --tail

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%;">
      &nbsp;&nbsp; | &nbsp;&nbsp;&nbsp;&nbsp;
      <%= 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!

Community
  • 1
  • 1
sirramongabriel
  • 583
  • 1
  • 11
  • 27

1 Answers1

1

Turns out I fixed this dealing with a different issue.

I removed config.action_controller.asset_host = "http://www.name_of_site.com" from production.rb in order to get my assets working in production.

I'm unsure why but this also corrected the issue with not being able to logout on Heroku.

I posted this as an answer with hopes that it will help someone in the future dealing with a similar issue.

sirramongabriel
  • 583
  • 1
  • 11
  • 27