I have a controller and a view (no ActiveRecord for this one). The controller calculates the current time in several places in the world and the view presents them.
I'd like to add a button that will make the clocks update. Adding a regular button which refreshes the whole page works fine, but I'd like to do that asynchronously using AJAX.
I've tried to use form_remote_tag
, but then nothing happens because nothing gets refreshed...
How do I do that?
(BTW, I'm doing that for learning rails. There's no real need or requirement)
My code: The controller interesting part:
def index
utc_time = Time.now.getutc
@clocks = []
@clocks << ["USA - New York", utc_time - 60*60*5]
@clocks << ["England - London", utc_time]
end
The view interesting part:
<%= javascript_include_tag 'prototype' %>
<div id="clocks_div">
<% @clocks.each do |city, time| %>
<b><%=h city %></b>: <%=h get_formatted_time(time) %>
<br/>
<% end %>
</div>
<br/>
<% form_remote_tag do %>
<%= submit_tag "Refresh!" %>
<% end %>
Thanks for the help