本文介绍了注销在本地工作,但不在 Heroku 上工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我使用 devise 进行登录/注销.我注意到我的 sign_out 链接在本地工作得很好,但即使在我添加、提交和推送之后也无法在 Heroku 上工作.

So I'm using devise for login/logout. I noticed that my sign_out link is working just fine locally, but won't work on Heroku even after I've added, committed and pushed.

这是我在 Heroku 日志中看到的内容

Here is what I see in my Heroku logs

2014-04-23T22:16:09.987029+00:00 heroku[router]: at=info method=GET path=/users/sign_out host=peaceful-atoll-4795.herokuapp.com request_id=16559a9f-0cff-4179-8aeb-d393ae44de38 fwd="108.233.86.201" dyno=web.1 connect=60ms service=34ms status=404 bytes=1616

请注意,当它应该是 DELETE 时,它会尝试使用 GET 方法注销.当我的路由正确时,为什么它使用 GET 方法?

Note that it tries to use the GET method to sign out when it should be DELETE. Why is it using the GET method when my routes are correct?

耙路:

              Prefix Verb   URI Pattern                       Controller#Action
    new_user_session GET    /users/sign_in(.:format)          devise/sessions#new
        user_session POST   /users/sign_in(.:format)          devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format)         devise/sessions#destroy
       user_password POST   /users/password(.:format)         devise/passwords#create
   new_user_password GET    /users/password/new(.:format)     devise/passwords#new
  edit_user_password GET    /users/password/edit(.:format)    devise/passwords#edit
                     PATCH  /users/password(.:format)         devise/passwords#update
                     PUT    /users/password(.:format)         devise/passwords#update

devise.rb 设置...

config.sign_out_via = :delete

我认为的链接代码

<% if user_signed_in? %>
  Logged in as <strong><%= current_user.email %></strong>.
  <%= link_to 'Edit profile', edit_user_registration_path, :class => 'navbar-link' %> |
  <%= link_to "Logout", destroy_user_session_path, method: :delete, :class => 'navbar-link'  %>
<% else %>
  <%= link_to "Sign up", new_user_registration_path, :class => 'navbar-link'  %> |
  <%= link_to "Login", new_user_session_path, :class => 'navbar-link'  %>
<% end %>

提前感谢您提供的任何资源或意见!

Thanks ahead of time for any of your resources or input!

推荐答案

所以,正如预期的那样,我的路由是正确的,但我的应用程序无法访问 jquery_ujs.

So, as expected my routes were correct, but my app was not able to access jquery_ujs.

jquery_ujs 有助于使 method::delete 工作.

为了提供 jquery_ujs 的正确路径,我将 gem 'rails_12factor', group::production 添加到我的 Gemfile 并运行 bundle install

In order to provide the correct path to jquery_ujs I added gem 'rails_12factor', group: :production to my Gemfile and ran bundle install

rails_12factor 还有助于在 Heroku 中提供静态资产.

rails_12factor also helps in serving static assets in Heroku.

感谢@MichaelSzyndel 提供的有用资源...

Thanks to @MichaelSzyndel for this helpful resource...

Heroku 上的 Rails 4 Asset Pipeline: https://devcenter.heroku.com/articles/rails-4-asset-pipeline

这篇关于注销在本地工作,但不在 Heroku 上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 07:32
查看更多