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

I am trying to integrate jQuery in Rails 3. I downloaded the rails.js file from http://github.com/rails/jquery-ujs and included this in my application. I have also included jQuery.

But when I try to make a simple page.replace like this:

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

I get the following error from javascript executable:

 RJS error: TypeError: Element.update is not a function Element.update("my_div", "mypartialdata"); 

Any ideas?

+4
source share
4 answers

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

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

http://github.com/aaronchi/jrails

If you want to use the assert_select_rjs test assistants in Rails 3, check out the revised version here:

https://github.com/theworkinggroup/jrails

+12
source

page.replace will call the prototype function Element.update . Do you have a prototype included in your page?

+1
source

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

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

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

0
source

I understood the problem. Obviously, with jQuery you cannot use rail assistants like replace_html or insert_html. You just need to make the page <<// JQuery Code.

-3
source

All Articles