Every Dog has one Blog


devise linkedin facebook google github twitter

Social Login integration with all the popular social networks in ruby on rails

Posted on .

I have seen a lot of people writing pretty messy code to integrate social logins in rails or get confused to integrate multiple social logins in rails. In order to help them, I have written a small application having integrations with Twitter + Facebook + Linkedin + Google + Github.

Here is the demo and here is the source code

I am using devise gem in this application. Few things to note in this:

  1. There are two models in this application a user model and an authorizations model and a user has_many authorizations.
  2. User can link to multiple social accounts from edit profile
  3. Once social accounts are linked, the user can log in from any connected social network.
  4. If the user tries to create an account with a different social network while in the logged out state. System maps it to the same account if that email address exists in the database else it will create a new account.
  5. Twitter doesn’t provide an email address of the user, nothing I can do about it.
  6. There are a lot of other commented out gems in the Gemfile. Those are the gems that I use a lot in my various projects. I will strongly suggest you check out those gems.

ruby-on-rails bundler

Parallel gem installing using Bundler

Posted on .

My bundler is running

No more waiting time. Bundler supports faster gem install as it adds support for parallel installation. You can pass in –jobs=SIZE (or -jSIZE) as a parameter to bundle install


validations, associations

Use belongs_to with presence validator

Posted on .

Assume we have two models: User and Image. User has one image and image belongs to a user. The code below:

class User < ActiveRecord::Base
  has_one :image

class Image < ActiveRecord::Base
  belongs_to :user

Now we want to add validation for the image to check if the user is there or not.


omniauth facebook ruby ruby-on-rails

Better way to parse user info from omniauth hash

Posted on .

Let’s assume we have to parse this hash. There can be the case we are not getting the keys as a response. So this post is about handling those cases.

auth = {
  :provider => 'facebook',
  :uid => '1234567',
  :info => {
    :nickname => 'jbloggs',
    :email => '',
    :name => 'Joe Bloggs',
    :first_name => 'Joe',
    :last_name => 'Bloggs',
    :image => '',
    :urls => { :Facebook => '' },
    :location => 'Palo Alto, California',
    :verified => true
  :credentials => {
    :token => 'ABCDEF...', # OAuth 2.0 access_token, which you may wish to store
    :expires_at => 1321747205, # when the access token expires (it always will)
    :expires => true # this will always be true

nokogiri ruby-on-rails

WARNING: Nokogiri was built against LibXML version 2.9.0, but has dynamically loaded 2.7.8

Posted on .

Have you ever seen this message while the Rails was loading up?

WARNING: Nokogiri was built against LibXML version x.x.x, but has dynamically loaded y.y.y

This will help you:

    bundle exec gem pristine nokogiri