在更改data-bind ="delete"后,为什么我的链接仍通过Post提交.滑轨 [英] Why is my link still submitting with Post when I've changed data-bind="delete" Rails

查看:123
本文介绍了在更改data-bind ="delete"后,为什么我的链接仍通过Post提交.滑轨的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下链接:

<a href="/kits?resource_id=536" class="authorize spin" data-method="post" data-remote="true" id="use_it_link_171" rel="nofollow">

创建工具包后,按如下所示更改链接:

After I create the kit I change the link as follows:

<a href="/kits/536" class="authorize spin" data-method="delete" data-remote="true" id="use_it_link_171" rel="nofollow">

我更改了href和数据方法,以便应将其提交给destroy动作.但是,它仍作为POST提交

I changed the href and the data-method so that it should submit to the destroy action. However its still being submitted as POST

为什么会这样,我该如何解决,以便将其提交为删除"?

Why is that and how can I fix this so its submits as a 'delete'?

推荐答案

这是因为Rails使用了不引人注目的JavaScript来设置<a data-remote="xxx"><a data-method="xxx">之类的标记的行为(实际上,Rails在您的页面中创建了一个隐藏形式,即点击链接后提交).通过 rails.js 在页面加载时完成.

It's because Rails uses unobstrusive javascript to set the behavior of tags like <a data-remote="xxx"> or <a data-method="xxx"> (in fact Rails creates an hidden form in your page that is submited when the link is clicked). It's done at page loading by rails.js.

因此,当您更改链接的data-method属性时,它太迟了",它不会更改链接的行为(您应该为此更新隐藏形式).您可以深入研究rails.js代码以找到实现方法,但是我建议您在页面中创建2个链接(一个使用data-method="post"和一个使用data-method="delete"),并使用CSS隐藏/显示仅有用的链接.链接.

So when you change the data-method attribute of the link, it's "too late", it does not changes the behavior of the link (you should update the hidden form for this). You could dig into rails.js code to find how to do it, but I suggest that you create 2 links in your page (one with data-method="post" and one with data-method="delete"), and use CSS to hide/display only the useful link.

这篇关于在更改data-bind ="delete"后,为什么我的链接仍通过Post提交.滑轨的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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