Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/84.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
Element.update不是函数[Rails 3+;JQuery]_Jquery_Ruby On Rails_Ruby On Rails 3_Ujs - Fatal编程技术网

Element.update不是函数[Rails 3+;JQuery]

Element.update不是函数[Rails 3+;JQuery],jquery,ruby-on-rails,ruby-on-rails-3,ujs,Jquery,Ruby On Rails,Ruby On Rails 3,Ujs,我正在尝试将JQuery集成到Rails 3中。我已经从下载了rails.js文件,并将其包含在我的应用程序中。我还包括JQuery 但是当我尝试做一个简单的页面时。请这样替换: render :update do |page| page.replace_html "my_div", :partial => "my_partial", :locals => {:mylocal => mylocal} end 我在执行javascript时遇到以下错误: RJS error

我正在尝试将JQuery集成到Rails 3中。我已经从下载了rails.js文件,并将其包含在我的应用程序中。我还包括JQuery

但是当我尝试做一个简单的页面时。请这样替换:

render :update do |page|
  page.replace_html "my_div", :partial => "my_partial", :locals => {:mylocal => mylocal}
end
我在执行javascript时遇到以下错误:

RJS error:
TypeError: Element.update is not a function

Element.update("my_div", "mypartialdata");

有什么想法吗?

页面。replace
将调用函数
元素。update
。你的页面中有原型吗?

我解决了这个问题。显然,对于JQuery,您不能使用rails帮助程序,如“replace\uHTML”或“insert\uHTML”。您只需像其他人所说的那样执行page,
page.replace
,在rails 2中,引用
Element.update

如果您想在Rails 3和jQuery中使用相同的帮助程序,请查看jrails:

如果您想使用Rails 3中的
assert\u select\u rjs
test helpers,请在此处获取补丁版本:


如果它真的只是
元素。在使用jQuery的rails 3中,使用
render(:update)
更新
东西,那么这个小js代码片段应该可以:

Element = function(){}
Element.update = function(id,html){$('#'+id).html(html);}
解析这个JS代码应该会有所帮助。 我把它放在
jquery\u ujs.js
文件的末尾