Skip to content

Instantly share code, notes, and snippets.

@rmahnovetsky
Created January 12, 2013 04:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rmahnovetsky/4516155 to your computer and use it in GitHub Desktop.
Save rmahnovetsky/4516155 to your computer and use it in GitHub Desktop.
Apotomo ajax widget example
module Apotomo
class AjaxWidget < Apotomo::Widget
responds_to_event :ajax_display
def display
render :view => :display
end
def ajax_display
render :text => "To be overridden"
end
end
<%= widget_div :id => "portlet-#{widget_id}" do %>
<div class="section">
<%= image_tag "loading.gif" %>
</div>
<% end %>
<script>
$(document).ready(function () {
$.ajax({
url: '<%= url_for_event(:ajax_display) %>',
dataType: 'html'
}).done(function(data, textStatus, jqXHR) {
$("#<%="portlet-#{widget_id}"%>").find(".section").html(data);
}).fail(function() {
$("#<%="portlet-#{widget_id}"%>").find(".section").html("error retrieving section");
});
});
</script>
class SiteTrafficWidget < Apotomo::AjaxWidget
def ajax_display
render :text => "Yey it works"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment