Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery Railscasts与Rails 3不兼容?需要帮助调试吗_Jquery_Ruby On Rails_Ruby_Debugging_Ruby On Rails 3 - Fatal编程技术网

Jquery Railscasts与Rails 3不兼容?需要帮助调试吗

Jquery Railscasts与Rails 3不兼容?需要帮助调试吗,jquery,ruby-on-rails,ruby,debugging,ruby-on-rails-3,Jquery,Ruby On Rails,Ruby,Debugging,Ruby On Rails 3,我看到一些评论说,该解决方案不适用于Rails3和jQuery,但这并不清楚。这是我在控制台中遇到的错误: Uncaught ReferenceError: add_fields is not defined (anonymous function)485:98 onclickd 它指向了一个很长很奇怪的链接: 我的视频节目视图中有此链接: <%= link_to_add_fields "New Comment Title", f, :comment_titles %> 这是my

我看到一些评论说,该解决方案不适用于Rails3和jQuery,但这并不清楚。这是我在控制台中遇到的错误:

Uncaught ReferenceError: add_fields is not defined
(anonymous function)485:98
onclickd
它指向了一个很长很奇怪的链接:

我的视频节目视图中有此链接:

<%= link_to_add_fields "New Comment Title", f, :comment_titles %>
这是my application.js中的添加字段功能:

function add_fields(link, association, content) {  
        var new_id = new Date().getTime();  
        var regexp = new RegExp("new_" + association, "g");  
        $(link).parent().before(content.replace(regexp, new_id));  
    }
我几乎是从railscast复制粘贴的,所以我不知道发生了什么

我怎样才能解决这个问题?您还希望看到哪些其他代码?

因此它看起来像:

function add_fields(link, association, content) {  
    var new_id = new Date().getTime();  
    var regexp = new RegExp("new_" + association, "g");  
    $(link).parent().before(content.replace(regexp, new_id));  
}
必须位于document.ready()块的外部。

因此看起来:

function add_fields(link, association, content) {  
    var new_id = new Date().getTime();  
    var regexp = new RegExp("new_" + association, "g");  
    $(link).parent().before(content.replace(regexp, new_id));  
}

必须在document.ready()块的外部。

您的问题似乎出现在application.js中,因此请修复它,您可以在之后调用add\u fields方法。您的问题似乎出现在application.js中,因此请修复它,您可以在之后调用add\u fields方法。这是因为add\u fields不是匿名函数。在文档准备就绪之前,它会在单击链接时应用。这是因为添加字段不是匿名函数。在文档准备就绪之前,它会在单击链接时应用。