Rails js.erb无法正常工作

编程入门 行业动态 更新时间:2024-10-28 04:17:21
本文介绍了Rails js.erb无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在提交一个表单,其中有一些复杂的嵌套到Rails控制器.Java语言与提交"按钮绑定在一起,如下所示:

I'm submitting a form, with somewhat complex nesting to a Rails controller. The Javascript is tied to the submit button as below:

$('#new_search').submit(function() { var valuesToSubmit = $(this).serializeArray(); $.ajax({ type: "POST", url: $(this).attr('action'), //sumbits it to the given url of the form data: valuesToSubmit, dataType: "POST" }) return false; // prevents normal behaviour });

Rails控制器可以很好地处理这些参数,并且所有参数都应在其应有的位置.

The Rails controller handles this fine and the parameters are all where they should be.

然后我渲染一个js.erb文件:

I'm then rendering a js.erb file:

respond_to do |format| format.js { render '/searches/update_search_results.js.erb' } end

并且日志显示确实已渲染:

and the log shows this has indeed rendered:

Rendered searches/update_search_results.js.erb (0.3ms)

但是在这个文件中(我已经仔细检查了文件名),甚至是一个简单的

But in this file (I've doubled checked the file name) even a simple

alert("hello world");

没有开火.控制台日志中没有Javascript错误.任何人有任何建议吗?与发送Ajax请求的原始Java脚本有关系吗?谢谢你的帮助

is not firing. There are no Javascript errors in the console log. Anyone got any suggestions? Something to do with the original Javascript that sends the Ajax request? thanks for any help

推荐答案

好,通过在视图的表单定义中返回旧样式:remote => true来解决此问题.

OK, fixed it by going back to the old style :remote => true in the form definition in the view.

我认为世界已经从这个问题转移到了毫不夸张的JS提交事件.显然我错了,但是此解决方案可能会对某人有所帮助,所以我将其留在这里

I thought the world had moved away from this to unobtrusive JS bouncing off the submit event. Obviously I was wrong but this solution might help someone so I'm leaving it here

更多推荐

Rails js.erb无法正常工作

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

发布评论

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

>www.elefans.com

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