开发者

Call rails method periodically

I want a rails method to be called automatically whenever t开发者_如何转开发he contents of a textfield is changed, or every n seconds. How can I do this? The method is on the object's model definition. Also, how can I get the content of the textfield?

Thanks.


You may also use built-in rails helpers and write something like

<%= periodically_call_remote :url => {:controller=>'mailbox',
                                        :action => 'get_newest_messages'},
        :frequency => 15
%>

And then in the specified controller you may call needed method of a model.


This will require using some javascript. I use the jQuery library to help me along. I would search the net ('Google') "rails jquery" for some tutorials.

Or if you prefer another library check out Best javascript libraries to work with rails?

Once you have your javsacript library in place you will need some sort of script to monitor the input. One way is to use a keyup event to listen for activity. This script will then post your data to the server via ajax.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜