gem Devise注销不适用于Heroku,但可以进行开发

时间:2018-09-16 18:07:47

标签: ruby-on-rails heroku devise

我无法让我的退出按钮在heroku应用上正常工作。

Js代码

    //= require jquery
    //= require jquery_ujs
    //= require turbolinks
    //= require bootstrap-sprockets
    //= require popper
    //= require_tree . 

这是我的Routes.rb

    Rails.application.routes.draw do
    devise_for :users
       as :user do
      get "signin" => 'devise/sessions#new'
     delete "sign_out" => 'devise/sessions#destroy'
     get 'signup' => 'devise/registrations#new'
      end
      root'home#index'
       get 'about' => 'home#about'
       get'pricing' => 'home#pricing'
        get 'contact' => 'home#contact'
        get 'about'  =>  'home#about'

这是我的Application.html.erb

 <ul class="navbar-nav">
      <li class="nav-item"><%= link_to "Home", root_path, class: "nav-link" %></li>
      <li class="nav-item"><%= link_to "About", about_path, class: "nav-link" %></li>
      <li class="nav-item"><%= link_to "Pricing",pricing_path, class: "nav-link" %></li>
      <li class="nav-item"><%= link_to "Contact",contact_path, class: "nav-link" %></li>
      <li class="nav-item pull-md-right"><%= link_to "Sign In",signin_path, class: "nav-link" %></li>
      <li class="nav-item pull-md-right"><%= link_to "Log out", signout_path, :method =>:delete, class: "nav-link" %></li>

      <li class="nav-item pull-md-right"><%= link_to "Sign Up",signup_path, class: "nav-link" %></li>

    </ul>
  </div>
</nav>

所以我做错了什么,任何帮助都会很棒。

2 个答案:

答案 0 :(得分:0)

我认为您的链接有误,特别是destroy_user_session_path应该有效的路径。

<%= link_to "Log out", destroy_user_session_path, :method =>:delete, class: "nav-link" %>

答案 1 :(得分:0)

如果您想致电signout_path,则必须添加as: :signout这样的内容;

delete "sign_out" => 'devise/sessions#destroy', as: :signout