开发者

Rails 3, how to prevent ajax remote calls (jquery) with a link_to and :remote => true with JS

So I have a simple ajax call to a page:

= link_to 'click me', my_path, :onclick => "if ($('#go').val() == "ok") { alert('going'); } else { return false; }", :remote => true do

This works just fine, I see the alert only when my field with id "go" has ok in there... but the issue is that the remote action triggers every time no matter what.

If this was not a remote link it would work just fine, not going through with the link, but it does not seem to behave the same way with a :remote => true ?

How 开发者_开发百科can I achieve the expected result ?

Thanks,

ALex


The issue here is that the Rails UJS driver will see the data-remote and then perform the action because of a function like this in rails.js so perhaps try setting the property om your link inside the JS and remove the :remote => true. That might work however I dont know if rails.js would bind to that correctly or not.

Also, consider placing this JS in the application.js once you're done debugging just so you dont have inline JS all over your controllers.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜