设计destroy

编程入门 行业动态 更新时间:2024-10-26 10:26:59
本文介绍了设计destroy_user_session_path不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在我的ruby on rails应用程序中,用户使用devise退出时遇到了问题

In my ruby on rails application I've a problem for the user logout with devise

我有这个导航栏:

<% if current_user %> <nav class="top-bar" data-topbar role="navigation"> <ul class="title-area"> <li class="name"> <h1><%= link_to 'Prova CMS', articles_path %></h1> </li> <li class="toggle-topbar menu-icon"><a href="#"></a></li> </ul> <section class="top-bar-section"> <ul class="right"> <li><%=link_to 'Gestisci Articoli', articles_path %></li> <li><%=link_to 'Gestisci Categorie', categories_path %></li> <li class="has-dropdown"> <a href="#"><%= current_user.email %></a> <ul class="dropdown"> <li><%= link_to "Logout", destroy_user_session_path, :method => :delete %></li> </ul> </li> </ul> <% if current_page?(articles_path) %> <ul class="left"> <div class="large-12 columns"> <%= form_tag articles_path, :id => "articles_search" , method: 'get' do %> <%= text_field_tag :search, params[:search], :placeholder => "Cerca per titolo"%> <% end %> </div> </ul> <% end %> </section> </nav> <% else %> <nav class="top-bar" data-topbar role="navigation"> <ul class="title-area"> <li class="name"> <h1><%= link_to 'Prova CMS', root_path %></h1> </li> <li class="toggle-topbar menu-icon"><a href="#"></a></li> </ul> <section class="top-bar-section"> <ul class="right"> <li><%= link_to 'Login', new_user_session_path%></li> </ul> </section> </nav>

。 在某些页面中,注销链接不起作用,并且它们在视图的url上生成一个Hashtag(例如,如果我在Articles_path localhost:3000 / articles上,则该链接在/ articles->附近添加# / articles#)

that i render in the application layout of the site (application.html.erb). In some page the logouts links doesn't works and they generate a Hashtag on the url of the views (for example if i'm on the articles_path localhost:3000/articles the link add # near the /articles -> /articles#)

该字符串未注释:

# The default HTTP method used to sign out a resource. Default is :delete. config.sign_out_via = :delete

在application.js中,我已经拥有了所有jQuery链接工作正常:

and in the application.js i've got all the jquery links working fine:

// This is a manifest file that'll be compiled into application.js, which will include all the files // listed below. // // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path. // // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the // compiled file. // // Read Sprockets README (github/rails/sprockets#sprockets-directives) for details // about supported directives. // //= require jquery //= require jquery_ujs //= require foundation //= require turbolinks //= require_tree . $(function(){ $(document).foundation(); });

最后,这是我的路线:

Rails.application.routes.draw do get 'show/index' root to: "show#index" devise_for :users resources :categories resources :articles end

推荐答案

我认为您的问题可能与Turbolink有关。尝试为此页面禁用涡轮链接以验证是否是这种情况。在您的身体标签上添加:

I think your issue may be related to turbolinks. Try disabling turbolinks for this page to validate whether this is the case. To your body tag add:

<body data-no-turbolink="true">

我相信Turbolinks将您的注销链接视为标准页面链接,从而阻止了实际功能的触发

I believe that turbolinks is treating your logout link like a standard page link, preventing the actual functionality firing

编辑

如果您证明是这种情况,请重点禁用Turbolink

If you prove this is the case, focus disabling turbolinks to just the specific link that causes problems and remove the attribute from the body.

<%= link_to "Logout", destroy_user_session_path, :method => :delete, :data => { :no_turbolink => true } %>

更多推荐

设计destroy

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

发布评论

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

>www.elefans.com

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