问题
I'm doing a tutorial for rails animated loading page but the problem is that I get the following message undefined method `remote_function'.I've done some research and it seems that "remote_function" is deprecated.Can anyone tell me please how to I make the code work on rails 3.1 :
onload="<%= remote_function(:url => { :action => :get_content_to_display } ) %>"
Thanks for helping
回答1:
Rails 3.1 prefered to use unobtrusive javascript. So you should use javascript framework (for ex. JQuery) to achieve your goal.
In old version of Rails remove_function just sent AJAX request to server when it was called.
So you can do something like this:
$(document).ready ()->
$.get "your_url", ()->
#handle response
Hope it will help you. And here is some additional info: JQuery.get()
回答2:
For quick fix of using prototype function in rails 3.1, add prototype_helper in your helpers folder the remote_function will be working fine then.
来源:https://stackoverflow.com/questions/8123325/remote-function-alternative-in-rails-3-1