Hi,
I want a rails method to be called automatically whenever the 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.
Hi,
I want a rails method to be called automatically whenever the 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.
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 http://stackoverflow.com/questions/951141/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.
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.