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 “private_pub.ru”. We have to change the content of private_pub.yml to below one

production:
secret_token: “batkaro”
signature_expiration: 86400 # one day

We got “server: http://fayeserver.herokuapp.com/faye ” from private_pub server setup. Because private pub is running on this server.

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

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 http://batkaro.herokuapp.com
Also you can checkout my github code at https://github.com/Hareramrai/batkaro

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 http://ramfayeserver.herokuapp.com/faye -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: “http://ramfayeserver.herokuapp.com/faye”
    secret_token: “batkaro”

    Please help me for that
    Thanks

  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:

    PrivatePub.sign({“server”:”http://ramfayeserver.herokuapp.com/faye”,”timestamp”:1375349302714,”channel”:”/messages/new1″,”signature”:”fe94de6212ab2a1a73b12a1c5802132fc4756780″});

    I am checking my application with your private_pub server.

    Please help me .

    Thanks
    Arun

  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.

    Thanks

  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 .

    Thanks

Leave a comment