remote_function alternative in rails 3.1

被刻印的时光 ゝ 提交于 2019-12-11 15:37:55

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!