Skip to content

Instantly share code, notes, and snippets.

@kylewelsby
Created August 18, 2011 14:50
Show Gist options
  • Save kylewelsby/1154209 to your computer and use it in GitHub Desktop.
Save kylewelsby/1154209 to your computer and use it in GitHub Desktop.
Pushing a partial though Pusher
...
var Server = Pusher.new('api_key', 'channel');
// option 1
Server.bind('event',function(data){
console.log("data received");
});
/* option 2
Re Build your element
*/
Server.bind('event',function(data){
var strong = $("<strong>",{
text: data.user.name
}),
link = $("<a>",{
href:"#"
});
link.append(strong);
$("#box_"+data.app.name+"_app_"+data.name).html(link);
});
/* Option 3
Build on request.
*/
Server.bind('event',function(data){
$(data.tag).html(data.html);
});
...
...
def update
@platforms = Platform.find parmas[:id]
#Option 1
Pusher['event'].trigger($Q{$("#box_qa_app_geolocation").html("<%= escape_javascript(render :partial => "/shared", :object => @platform) %>");})
#Option 2
Pusher['event'].trigger(@platforms.to_json)
#Option 2
data => {
:html => escape_javascript(render (:partial => "/shared", :object => @platform)),
:tag => "box_#{@platform.name}_app_#{@platform.app.name}"
}.to_json
Pusher['event'].trigger(data) # might work?
end
...
@pcv2
Copy link

pcv2 commented Dec 12, 2011

In option 3, I had to turn it to $(data.tag).html(data.html.join(', '); because html only accepts an html string as an argument not an array.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment