开发者

Element.update is not a function [Rails 3 + JQuery]

开发者 https://www.devze.com 2023-01-13 20:21 出处:网络
I\'m attempting to integrate JQuery into Rails 3.I\'ve downloaded the rails.js file from http://github.com/rails/jquery-ujs and have included it in my app.I\'ve also i开发者_如何学运维nclude JQuery.

I'm attempting to integrate JQuery into Rails 3. I've downloaded the rails.js file from http://github.com/rails/jquery-ujs and have included it in my app. I've also i开发者_如何学运维nclude JQuery.

But when I attempt to do a simple page.replace like so:

render :update do |page|
  page.replace_html "my_div", :partial => "my_partial", :locals => {:mylocal => mylocal}
end

I get the following error thrown from the javascript executing:

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

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

Any ideas?


As others have said, page.replace, in rails 2, references Element.update.

If you want the same helpers available to you in Rails 3 with jQuery, check out jrails:

http://github.com/aaronchi/jrails

In case you want to use the assert_select_rjs test helpers in Rails 3, go grab the patched version here:

https://github.com/theworkinggroup/jrails


page.replace will call prototype function Element.update. Have you got prototype included in your page?


If it really is just the Element.update thing using render(:update) in rails 3 with jQuery, this little js code snippet should do it:

Element = function(){}
Element.update = function(id,html){$('#'+id).html(html);}

parsing this JS code should help. I've put it at the end of the jquery_ujs.js file.


I figured out the problem. Apparently with JQuery, you cannot use the rails helpers like "replace_html" or "insert_html". You merely have to do page << "//Jquery code".

0

精彩评论

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