注销不能在Heroku上工作 - 使用Devise宝石和Rails 4 [英] Sign Out not working on Heroku - using Devise gem and Rails 4

查看:101
本文介绍了注销不能在Heroku上工作 - 使用Devise宝石和Rails 4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚部署到Heroku的Rails 4应用程序,它使用Devise进行身份验证。注册本地工作,但Heroku返回错误您正在寻找的页面不存在,它不记录用户。

I just did an initial deploy to Heroku of a Rails 4 app that uses Devise for authentication. Signing out works locally, but Heroku returns an error that "The page you were looking for does not exist," and it doesn't log the user out.

根据Heroku日志和Google / SO搜索,看起来原因是Heroku正在使用GET请求而不是DELETE - 虽然我的应用程序代码指定:删除链接的方法,而Devise默认使用DELETE注销。有些文章建议Heroku使用GET,以便用户可以在没有启用JavaScript的情况下登录,但是我的代码中包含了JS include标签,并且在浏览器中启用了JS。 (我已经检查过使用Chrome和Safari。)

Based on the Heroku logs and a Google/SO search, it looks like the reason is that Heroku is using a GET request instead of DELETE - though my app code specifies the :delete method for the link, and Devise uses DELETE for signing out by default. Some articles suggested that Heroku uses GET so that users can sign out without having JavaScript enabled, but I have the JS include tag in my code and JS is enabled in my browser. (I've checked using both Chrome and Safari.)

我发现更改配置的说明,以便Devise使用:get而不是:delete,但是更喜欢使用更安全的:删除方法,如果可能的话。

I've found instructions for changing the configuration so that Devise uses :get instead of :delete, but I would prefer to use the more secure :delete method if at all possible.

感谢您的想法。回答你的问题:

Thanks for the ideas so far. In response to your questions:

这是我的链接:

<%= link_to "Log out", destroy_admin_session_path, method: :delete %>

这是我在头文件中加载javascript:

This is what I have in the head tag to load the javascript:

  <%= javascript_include_tag "application", "data-turbolinks-track" => true %>

在控制台中没有报告JS错误。

There are no JS errors reported in the console.

推荐答案

我找到了解决方案。问题是Rails 4处理与Rails 3不同的资产。默认情况下,Rails 4不提供静态资产。您可以在config / application.rb中手动更改此设置:

I found the solution. The problem is that Rails 4 handles assets differently than Rails 3. By default, Rails 4 doesn't serve static assets. You can manually change this in config/application.rb by setting:

config.serve_static_assets = true

另一个选项(和Heroku建议的)是使用rails_12factor gem。将其添加到您的Gemfile并运行捆绑安装将为您进行调整,并将您的记录器设置为标准。它可以与Rails 3和Rails 4一起使用。

Another option (and the one that Heroku recommends) is to use the rails_12factor gem. Adding this to your Gemfile and running bundle install will make the adjustment for you and also set your logger to standard out. It can be used with Rails 3 and Rails 4 both.

gem 'rails_12factor', group: :production

我选择使用宝石。运行捆绑安装后,承诺更改,并重新部署 - 我的登出链接工作正常,无需更改方法。此后,我的scss文件也被准确地编译和实现。 (我以前没有做过任何样式,所以我没有意识到这是一个问题,有趣的是遇到一个新的问题可以帮助导致一个解决方案...)

I opted to use the gem. After I ran bundle install, committed the changes, and redeployed - my sign out link worked fine with no need to change the method. My scss files were also compiled and implemented accurately after this. (I hadn't done anything with the styles before, so I didn't realize this was an issue. Funny how encountering a new problem can help lead to a solution...)

这是帮助我的资源:

https://devcenter.heroku.com/articles/rails-4-asset-pipeline

https://github.com/heroku/rails_12factor

这篇关于注销不能在Heroku上工作 - 使用Devise宝石和Rails 4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆