The best approach is to never put Ruby variables into your JavaScript.
I prefer to use data attributes in the DOM to pass values from the server to the client code:
<div class='my-pubnub-widget' data-pubnub-opts= '<%= @ruby_hash.to_json %>'></div>
And in JavaScript
function setupPubnub(opts) {
pubnub.subscribe({
channel : opts.channel,
message : function(message){
if(message.customer_id == opts.id){
$('#message').append($('<li>').text(opts.first_name + ': (' + opts.time + ') '+ message.text));
}
}
});
}
$(document).on('page:load', function () { // turbolinks ready event
$('.my-pubnub-widget').each(function () {
setupPubnum($(this).data('pubnub-opts'));
});
});