Skip to content

Instantly share code, notes, and snippets.

@Woody88
Created July 19, 2015 09:20
Show Gist options
  • Save Woody88/484dcda7ac7aec1afab1 to your computer and use it in GitHub Desktop.
Save Woody88/484dcda7ac7aec1afab1 to your computer and use it in GitHub Desktop.
## Retrieve all posts on dashboard load
ajax1 =
$.ajax
async: true
type: 'GET'
url: '/posts.json'
success: (data) ->
$.when(ajax1, ractive).done (a1) ->
posts = a1[0]
i = 0
while i < posts.length
ractive.push('list', posts[i])
i++
## New Post ##
$('#new_post').on 'click', (e) ->
e.preventDefault()
send($('#message').val())
$('#message').val('')
dispatcher = new WebSocketRails($('#posting').data('uri'), true)
dispatcher.on_open = (data) ->
console.log('Connection has been established: ', data);
channel = dispatcher.subscribe 'posts'
### Due to format_post call in the controller this function is not called anymore, not sure why..###
channel.bind 'new_post', (message) ->
console.log("inside!")
ractive.unshift('list', message)
send = (message) ->
dispatcher.trigger 'posting', message
ractive = new Ractive
el: '.all_posts'
template: '#template'
data: {list:[]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment