2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'app/helpers/async_helper.rb', line 2
def asynchronously
id = Time.new.to_i
id = "#{ id }#{ AsyncCache.instance.counter }"
safe_concat %{
<div id="#{id}">
Loading... #{ image_tag('spinner.gif') }
</div>
<script>
$(function () {
$.getJSON(
"/async/#{id}",
function (data) {
$('##{id}').html(data.content)
}
);
});
</script>
}
AsyncCache.instance.schedule do
_content = capture do
yield
end
AsyncCache.instance.write(id, _content)
end
end
|