简体   繁体   English

rails - link_to同一页但有锚 - >没有重载

[英]rails - link_to same page but with anchor -> no reload

I want to use 我想用

link_to 'Cancel', edit_project_path(@project, url_options)

to cancel the edit and go back to the edit page. 取消编辑并返回编辑页面。

I use jQuery UI Tabs for a tabbed edit page. 我使用jQuery UI选项卡作为选项卡式编辑页面。 Each tab has it's own form and submit/cancel buttons. 每个选项卡都有自己的表单和提交/取消按钮。

When I click a Cancel link I want to go back to the active tab . 当我单击取消链接时,我想返回活动选项卡 So I set 所以我订了

url_options = {:anchor => active_tab_id}

The problem is: the page doesn't reload because of the anchor. 问题是:由于锚点,页面没有重新加载。 Adding data-no-turbolink does not help: 添加data-no-turbolink 没有帮助:

link_to 'Cancel', edit_project_path(@project, url_options), :data => {:no_turbolink => true}

try using 尝试使用
<%=link_to("Cancel", edit_project_path(@project, url_options), method: :get)%> this helped me better <%=link_to("Cancel", edit_project_path(@project, url_options), method: :get)%>这对我有所帮助

The only way to do it is with javascript. 唯一的方法是使用javascript。

Add custom data attribute to the link: 将自定义数据属性添加到链接:

link_to 'Cancel', edit_project_path(@project, url_options), :data => { :reload => true }

Then put this javascript somewhere, for example in app/javascripts/reload_hash.js 然后把这个javascript放在某处,例如在app / javascripts / reload_hash.js中

    $(function(){
        $('a[data-reload="true"').on('click', function(e) {
            window.location = $(e.target).attr('href');
            window.location.reload(true);
        });
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM