我正在接受追踪以下修复的挑战:
我可以在我的开发环境中登录/注销
我无法在我的制作环境中退出
我看过并尝试过以下问题的解决方案:
我注意到heroku日志中的SQL就是说选择员工,其中deleted_at为空,否则只要看到对会话#new的GET请求,我点击'注销'。
这是我的代码:
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 (添加了这些配置)
Rails.application.configure do
config.cache_classes = true
config.assets.compile = true
config.assets.digest = true
end
提前感谢志愿参加一套新鲜的眼睛!
答案 0 :(得分:0)
原来我解决了这个处理不同的问题。
我从production.rb中删除了config.action_controller.asset_host = "http://www.name_of_site.com"
,以便让我的资产在生产中运行。
我不确定原因,但这也纠正了无法注销Heroku的问题。
我发布了这个答案,希望它能帮助将来处理类似问题的人。