Skip to content

Instantly share code, notes, and snippets.

@ceritium
Forked from rmahnovetsky/ajax_widget.rb
Created June 30, 2021 21:11
Show Gist options
  • Save ceritium/a7bcd96b49663384891672cde429efc5 to your computer and use it in GitHub Desktop.
Save ceritium/a7bcd96b49663384891672cde429efc5 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