设计注销不起作用(Devise logout not working)

编程入门 行业动态 更新时间:2024-10-22 19:50:57
设计注销不起作用(Devise logout not working)

我正在使用最新版本的devise和rails 4.2.4。 我是我的主页

public/index.html

其中包含大量的javascript。 但是当我从其他页面加载它时,它不会加载所有效果。 包括在内

$(document).on('page:load', ready); <script src="/js/modernizr-2.6.2.min.js"></script> <script src="/js/main.js"></script>

在application.js文件中。 但随后退出

<%= link_to "Logout",destroy_user_session_path, method: :delete %>

不起作用! 它被渲染为GET / users / sign_out。

当我从application.js中删除这些链接时,它工作正常。

针对此问题的任何解决方法?

I'm using the latest version of devise and rails 4.2.4. I've my home page

public/index.html

which contains heavy javascript. But when I load it from some other page, it doesn't load with all the effects. So included

$(document).on('page:load', ready); <script src="/js/modernizr-2.6.2.min.js"></script> <script src="/js/main.js"></script>

in application.js file. But then Logout

<%= link_to "Logout",destroy_user_session_path, method: :delete %>

doesn't work! It gets rendered as GET /users/sign_out.

When I remove those links from application.js, it works fine.

Any workaround for this issue?

最满意答案

你的javascript中有错误。

-

每次使用method: :delete或method: :patch ,Rails使用相应的动词填充表单, 使用Javascript正确设置:

[link_to]动态创建HTML表单并立即使用指定的HTTP谓词提交表单进行处理。 有用的是让链接在危险的操作中执行POST操作,例如删除记录(搜索机器人可以在抓取您的站点时遵循这些操作)。 支持的动词有:post,:delete,:patch和:put。 请注意,如果用户禁用了JavaScript,请求将回退到使用GET

如果你的javascript被破坏了以上情况(IE你有一个错误阻止它在页面上正常工作)。

-

由于你还没有发布你的JS,我不能给你任何细节。

但是,我可以说你的JS应该尽可能不引人注目 。

在Rails应用程序中的任何地方使用<script>是不好的做法; 你应该在你的application.js使用sprockets manifest指令连接文件:

#app/assets/javascripts/application.js //= require main //= require modernizr

Your javascript has an error in it.

--

Each time you use method: :delete or method: :patch, Rails populates a form with the appropriate verb, using Javascript to set it correctly:

[link_to] dynamically creates an HTML form and immediately submit the form for processing using the HTTP verb specified. Useful for having links perform a POST operation in dangerous actions like deleting a record (which search bots can follow while spidering your site). Supported verbs are :post, :delete, :patch, and :put. Note that if the user has JavaScript disabled, the request will fall back to using GET

The above is true if your javascript is broken (IE you have an error preventing it from working properly on the page).

--

Since you haven't posted your JS, I cannot give you any specifics.

However, I can say that your JS should be as unobtrusive as possible.

Using <script> anywhere in your Rails app is bad practice; you should have the files concatenated in your application.js with the help of sprockets manifest directives:

#app/assets/javascripts/application.js //= require main //= require modernizr

更多推荐

本文发布于:2023-07-18 04:40:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1154898.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不起作用   Devise   working   logout

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!