Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save oferreiro/0445bb6486f7609999a7 to your computer and use it in GitHub Desktop.
Save oferreiro/0445bb6486f7609999a7 to your computer and use it in GitHub Desktop.
Render a javacript on rails with haml.js
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
jQuery ->
setInterval(->
console.log "Getting table..."
$.ajax(
url: "/"
dataType: "script"
type: "GET"
).done (data) ->
console.log data
,10000)
%table#reload-table
%tr
%th Alias
%th Hostname
%th
%th
%th
- @registers.each do |register|
%tr
%td= register.alias
%td= register.hostname
%td= link_to 'Show', register
%td= link_to 'Edit', edit_register_path(register)
%td= link_to 'Destroy', register, :method => :delete, :data => { :confirm => 'Are you sure?' }
%h1 Listing registers
= link_to "table via js", registers_path, remote: true
= render "table"
%br
= link_to 'New Register', new_register_path
:plain
(function() {
jQuery(function() {
console.log("reloading table");
$("#reload-table").html("#{escape_javascript render 'table'}");
});
}).call(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment