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
Advertisements

Setup PrivatePub or Faye on heroku

In this post I am  going to show how to setup private_pub server on heroku. Private Pub gem is a very nice solution for pushing real time data and it’s open-source . For using the private_pub gem we have to create two application on heroku. First one for our rails app and second one for private_pub server.

Folder structure for private_pub server application is like the below one

fayeserver

config ———–> private_pub.yml
                            application.rb
                            boot.rb
script ————> rails

Gemfile

Gemfile.lock

Procfile

private_pub.ru

Note: bold represent folder and other represent file.

“private_pub.yml” and “private_pub.ru” are created by private_pub gem using rails g private_pub:install

Gemfile has following gems

source ‘https://rubygems.org
    gem ‘rails’,’3.2.12′
    gem ‘private_pub’
    gem ‘thin’
    gem ‘foreman’
After adding the gem ,  bundle it. Then run “rails g private_pub:install”.
Initialize the repository by git init.
After that create a heroku app using “heroku apps:create fayserver”. I am using app name as “fayserver” but it can be changed.
Then change the private_pub.yml file content to
production:
  secret_token: “batkaro”
  signature_expiration: 86400 # one day
After that commit the code and push the code to heroku .
Now finally  we are ready to  use it. 🙂

You can checkout my github repository for fayserver code