注销在本地工作,但不在Heroku上工作

时间:2014-04-23 22:23:17

标签: ruby-on-rails heroku devise

所以我正在使用设计登录/注销。我注意到我的sign_out链接在本地运行得很好,但即使在我添加,提交和推送之后也无法在Heroku上运行。

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

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

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

佣金路线:

              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 %>

提前感谢您的任何资源或输入!

4 个答案:

答案 0 :(得分:3)

因此,正如预期的那样,我的路线是正确的,但我的应用无法访问jquery_ujs

jquery_ujs有助于method: :delete工作。

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

rails_12factor也有助于在Heroku中提供静态资源。

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

在Heroku上的Rails 4资产管道: https://devcenter.heroku.com/articles/rails-4-asset-pipeline

答案 1 :(得分:1)

盲目回答,因为我不能评论stackoverflow。 :P很高兴看到applicaiton.js文件以确保。

Rails&gt;〜4.0

您可能需要将rails_12_factor gem包含在gemfile中。这是因为rails 4默认不会提供静态资产,因此可能存在问题。请在此处查看:https://github.com/heroku/rails_12factor#rails-4-serve-static-assets

Rails&gt; ~4.1

您需要将资产预编译声明到application.rb或assets和.rb初始值设定项中。这需要使开发模式与生产模式匹配。链轮改变。检查一下:https://github.com/rails/sprockets-rails/pull/84

答案 2 :(得分:1)

在Heroku上使用Rails 5为我工作的解决方案是简单地按如下方式重新排序js文件:

//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require bootstrap-sprockets

答案 3 :(得分:0)

快速修复,

config.sign_out_via = :delete

config.sign_out_via = :get
在config / devise.rb中

可悲的是,它在生产模式下运行良好。但它会在开发模式中出现错误。

这是解决方案的原始链接。
Ruby on Rails: Unable to sign out of application in production