Skip to content

Instantly share code, notes, and snippets.

@VictorTpo
Last active August 29, 2015 14:25
Show Gist options
  • Save VictorTpo/fb01516df0393315f149 to your computer and use it in GitHub Desktop.
Save VictorTpo/fb01516df0393315f149 to your computer and use it in GitHub Desktop.

Faye & Rails 4

This gist describes how to implement faye with a rails 4 application.

What I want ?

A user receives a live notification when another user login.

Requirements

A rails 4 application with devise for user management

2 gems:

A jquery plugin to notify my users like http://notifyjs.com/

Installation

1 - Gemfile

After gems thin and faye have been added to Gemfile make bundle install

2 - Configure Faye server and start it

Create a faye.ru file and launch you server with rackup faye.ru -s thin -E production

3 - For the client, Add faye.js to application.html.erb

Just read the file : application.html.erb and add <%= javascript_include_tag "http://localhost:9292/faye.js" %>

4 - Permit a browser to establish a connection with faye server

Add faye_websocket.js on your app/assets/javascripts folder

5 - Application.js

Load previous file on application.js

6 - FayeNotification Service Object

Add a service object to publish a message to a faye channel without use EventMachine

7 - Finally

Call FayeNotification after a user login with application_controller.rb and its after_sign_in_path_for method

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