我的rails应用程序成功注销用户,并在开发模式下重定向到about页面。但是,当我将其部署到生产环境时,它会返回302状态和显示"您正被重定向的页面"。我使用设计进行身份验证是我的代码实际上是什么样的。
路线
Rails.application.routes.draw do
devise_for :users, controllers: { registrations: "users/registrations", confirmations: "users/confirmations", sessions: "devise/sessions" }, skip: [:sessions]
devise_scope :user do
get "login" => "devise/sessions#new", as: :new_user_session
post "login" => "devise/sessions#create", as: :user_session
get "/join" => "users/registrations#new", as: :join
get '/logout', to: "devise/sessions#destroy", as: :destroy_user_session
end
resources :companies
get "/about", to: "pages#about"
get "/faq", to: "pages#faq"
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
root 'pages#home'
end
我的application_controller.rb
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
include SessionsHelper
protected
def after_sign_in_path_for(resource)
company_path(resource)
end
def after_sign_out_path_for(resource_or_scope)
"/about"
end
def store_location
session[:return_to] == request.full_path
end
def clear_stored_location
session[:return_to] = nil
end
def redirect_back_or_to(alternate)
redirect_to(session[:return_to] || alternate)
clear_stored_location
end
end
最后我的链接退出。
<%= link_to "Log out", destroy_user_session_path %>
请注意,我正在使用设计4.2.0和capistrano进行部署。
此致
〜
答案 0 :(得分:0)
我必须覆盖设计会话#controller并将我的路线更改为:
delete 'logout', to: "users/sessions#destroy", as: :destroy_user_session
然后我在我的链接中添加了删除方法以便注销。