How to use private_pub gem on heroku in ruby on rails

In this post I am going to show how to use private_pub gem on heroku. Before going to use it we have to setup private_pub server on heroku. Use this link to setup the server.

Private Pub gem is a very nice solution for pushing real time data and it’s open-source . Now create a rails app using “rails new demo_private_pub”. Then we have to add the gems given below

gem ‘private_pub’
gem ‘thin’

After adding the gem bundle it. Then use this “rails g private_pub:install” to create private_pub settings files. It will create two file “config/private_pub.yml” and “”. We have to change the content of private_pub.yml to below one

secret_token: “batkaro”
signature_expiration: 86400 # one day

We got “server: ” from private_pub server setup. Because private pub is running on this server.

Then we have to move file “” inside “config / initializers” of application.
After that remove the “run PrivatePub.faye_app” from “”.

Now we are ready use to private_pub.

Add this “//= require private_pub” to applications.js file.

<%= subscribe_to "/messages/new" %>  # use this for subscribing to a channel

<% publish_to "/messages/new" do %> # use this for publishing the data to a channel.
  $("#post-list-div").append("<%= j render(@post) %>");
<% end %>

You can checkout my live chat application at
Also you can checkout my github code at

7 thoughts on “How to use private_pub gem on heroku in ruby on rails

  1. Hello!

    My application is working proper on local host.But I am getting error on heroku.I am getting following error when I tried to post message through console.

    curl -d ‘message={“channel”:”/messages/new”, “data”:”hello”, “ext”:”secret”}’

    [{“channel”:”/messages/new”,”error”:”Incorrect token.”,”successful”:false}]cis@CISM189:~/Desktop/atradeship-chat$

    I have following setting in my private_pub.yml
    server: “”
    secret_token: “batkaro”

    Please help me for that

  2. Hello,

    Thanks for you reply.I found problem “subscribe_to” function was not working .now ok.

    I am facing another problem ,my application works fine on heroku but only chorme 12,16 version not on all browser.I have checked all the things.I debugg application and reason is that.faye post ajax request is not working.still i am able to see javascript in view source like:


    I am checking my application with your private_pub server.

    Please help me .


  3. I am facing problem with many days and found that application not working with https:// request.Demo still not working with https:// request .Please suggest me solution for that.


  4. Thanks for your reply,

    yes it is help full for me.I found solution for that my app requesting with https rather that http .Now my apps working fine with http request on heroku.Can you please suggest me how it will work with https .


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s