I hate signing up for websites. I’ve already signed up for so many, using different usernames, that going back to one of them and trying to remember my credentials is sometimes impossible. These days, most sites have begun offering alternative ways to sign up, by allowing you to use your Facebook, Twitter or even your Google account. Creating such an integration sometimes feels like a long task. But fear not, Oauth is here to help.

In this tutorial, i’m going to explain how to integrate these authentication providers into your Rails app. Here i use “omniauth” gem. Because Omniauth allows you to easily integrate more than sixty authentication providers, including Facebook, Google, Twitter and GitHub.

Step 1: Preparing your Appllication

Let’s create a new Rails application and add the necessary gems. I’m going to assume you’ve already installed Ruby on Rails 4.0 or latest using RubyGems.

Run this command in your terminal

rails new omniauth-tutorial

Now open your Gemfile and reference the omniauth gem.

gem 'omniauth'

Next, per usual, run the bundle install command to install the gem.

Step 2: Creating a Provider

In order to add a provider to Omniauth, you will need to sign up as a developer on the provider’s site. Once you’ve signed up, you’ll be given two strings (sort of like a username and a password), that needs to be passed on to Omniauth.

Step 3: Add your Providers to the App

Create a new file under config/initializers called omniauth.rb. We’re going to configure our authentication providers through this file.

Paste the following code into the file we created earlier

Rails.application.config.middleware.use OmniAuth::Builder do
 		provider << provider >>,
    Rails.configuration.<< provider >>_client_id,
	Rails.configuration.<< provider >>_secret_key ,
    << options >>

For example use the google provider then use the following

Rails.application.config.middleware.use OmniAuth::Builder do
 		provider :google_oauth2,
	Rails.configuration.google_secret_key , { :scope =>
	"userinfo.profile, userinfo.email, devstorage.full_control,
	compute", :prompt => 'consent'}

####Step 4: Creating the Login Page

Let’s create our sessions controller. Run the following code in your terminal to create a new sessions controller.

rails generate controller sessions

And add some actions in your controller. Next, open your config/routes.rb file and add this

get   '/login', :to => 'sessions#new', :as => :login
match '/auth/:provider/callback', :to => 'sessions#create'

Let’s break this down:

The first line is used to create a simple login form where the user will see a simple Connect with Provider link. The second line is to catch the provider’s callback. After a user authorizes your app, the provider redirects the user to this url, so we can make use of their data.

Open your app/controllers/sessions_controller.rb file and write the create method, like so

def create
  auth_hash = request.env['omniauth.auth']
  render :text => auth_hash.inspect

This is used to make sure everything is working. Point your browser to localhost:3000/auth/provider and you’ll be redirected to provider page so you can authorize your app. Authorize it, and you will be redirected back to your app and see a hash with some information.

####Step 5: Creating the User Model

In the Rails console (rails console), create the new model.

rails generate model User name:string email:string

For now, our user model will only have a name and an email. With that out of the way, we need a way to recognize the user the next time they log in.

####Step 6: Adding create action on controller

Let’s add some code to our sessions controller so that it logs a user in or signs them up, depending on the case. Open app/controllers/sessions_controller.rb and modify the create method, like so:

def create
 	 auth_hash = request.env['omniauth.auth']
 	 user_identity = User.find_by_email(auth_hash["info"] ["email"])
 	if user_identity
   render :text => "Welcome back #{user_identity.user.name}! You have already signed up."
   user = User.new :name => auth_hash["info"]["name"], :email => auth_hash["info"]["email"]
   render :text => "Hi #{user.name}! You've signed up."

We check whether an authorization exists for that provider and that email. If one exists, we welcome our user back.

If no authorization exists, we sign the user up. We create a new user with the name and email that the provider gives us, and we associate an authorization with the provider. Give it a test! Go to localhost:3000/auth/provider and you should see “You’ve signed up”. If you refresh the page, you should now see “Welcome back”.

####Step 7: Create html

Open app/views/sessions/new.html.erb and add

<%= link_to "Connect", "/auth/<< provider >>" %>

Chef is a configuration management and automation platform from Opscode. Chef helps you describe your infrastructure with code. Because your infrastructure is managed with code, it can be automated, tested and reproduced with ease.

Assumption: Ruby installed

Server Installation

The Chef server acts as a hub for configuration data. The Chef server stores cookbooks, the policies that are applied to nodes, and metadata that describes each registered node that is being managed by the chef-client. Nodes use the chef-client to ask the Chef server for configuration details, such as recipes, templates, and file distributions. The chef-client then does as much of the configuration work as possible on the nodes themselves (and not on the Chef server). This scalable approach distributes the configuration effort throughout the organization.

Download chef-server package from here https://downloads.chef.io/chef-server/

$ wget https://web-dl.packagecloud.io/chef/stable/packages/ubuntu/trusty/chef-server-core_12.0.1-1_amd64.deb

This will download the installation package that you can then install like this:

$ sudo apt-get update
$ dpkg -i chef-server-core_12.0.1-1_amd64.deb

This will install the server component on the machine. It prints to the screen afterwards that you should run this next command to actually configure the service around your specific machine. This will configure everything automatically:

$ sudo chef-server-ctl reconfigure

Verify chef-server installation by entering this command

$ sudo chef-server-ctl test

Once this step is complete, the server should be up and running. You can access the web interface immediately by typing https:// followed by your server’s domain name or IP address.


Because the SSL certificates were signed by an authority that your browser does not recognize by default, you will see a warning message appear. Click the “Proceed anyway” button to bypass this screen and access the login screen.

The default login credentials are as follows:

Default Username: admin
Default Password: p@ssw0rd1

Workstation Installation

Install chef using rubygems

$ gem install chef

We should setup a file structure that will help us organise our various Chef files. Opscode, the makers of Chef provide one. They call it simply the Chef Repository.

$ wget https://github.com/opscode/chef-repo/tarball/master
$ tar -zxf master
$ mv opscode-chef-repo* chef-repo
$ rm master If we look inside the chef-repo directory we can see the following:

$ cd chef-repo/
$ ls
config  cookbooks  data_bags  environments  nodes  Rakefile  README.md  roles

We can use the command knife to help us manage our cookbooks. First we should tell knife where to find our cookbooks directory.

$ mkdir chef-repo/.chef

download /etc/chef-server/chef-validator.pem and /etc/chef-server/admin.pem from chef-server to this chef-repo/.chef

Edit chef-repo/.chef/knife.rb

log_level                :info
log_location             STDOUT
node_name                admin
client_key               'chef-repo/.chef/admin.pem'
validation_client_name   'chef-validator'
validation_key           'chef-repo/.chef/chef-    validator.pem'
chef_server_url            'https://server_domain_or_IP'
cache_type               'BasicFile'
cookbook_path [ 'chef-repo/cookbooks' ]

Thats all :-) chef-setup is over.

Now you can check it from workstation with the below commands

knife client list
knife node list

Wondering what Git and Github are all about? Well,firstly:

Git and GitHub- What is the difference?

Git is a version control system; think of it as a series of snapshots(commits) of your code. You see a path of these snapshots, in which order they where created. You can make branches to experiment and come back to snapshots you took.

GitHub, is a web-page on which you can publish your Git repositories and collaborate with other people.It is the best place to share code with friends, co-workers, classmates, and complete strangers. Did you know that over eight million people use GitHub to build amazing things together?!(Now that’s something to read about,eh?)

Now let’s get started! Now that you know what is the difference between Git and Github,let us go ahead and set up your Git tool. It’s a simple 4 step process.(Piece of cake,really!)

How to setup Git tool:



Download the latest version of Git from the link mentioned above.


On your computer, open terminal.


Now, you need to tell Git your name so your commits will be properly labeled. Type the following:

$ git config --global user.name “Your name”


Tell Git the email address that will be associated with your Git commits. Type:

$ git config --global user.mail “Your mail”

Now that you’ve got your Git tool is setup. Let’s proceed. What next? FIRST THINGS FIRST!!

How do you create a Repository?

Create a new directory , open it and type

$git init

to create a new repository.(This is on your terminal ofcourse).



Hang on.

Fork?! What’s a fork?

A fork is a copy of a repository. Forking a repository allows you to freely experiment with changes without affecting the original project. Most commonly, forks are used to either propose changes to someone else’s project or to use someone else’s project as a starting point for your own idea. A great example of using forks to propose changes is for bug fixes. Rather than logging an issue for a bug you’ve found, you can: 1.Fork the repository.

2.Make the fix.

3.Submit a pull request to the project owner. If the project owner likes your work, they might pull your fix into the original repository! At the heart of open source is the idea that by sharing code, we can make better, more reliable software. In fact, when you create a repository on GitHub, you have a choice of automatically including a license file, which determines how you want your project to be shared with others.


1.On GitHub, navigate to the repository that you want to fork.

2. In the top-right corner of the page, click “FORK”. Now you have a fork of the original repository!

You might fork a project in order to propose changes to the upstream, or original, repository. In this case, it’s good practice to regularly sync your fork with the upstream repository.

So, right now, you have a fork of the repository that you want to make changes to, but you don’t have the files in that repository on your computer!So, let’s create a clone of your fork locally on your computer.


There are two ways to clone a repository in GitHub.

1.Using HTTPS:

To clone using HTTPS, type:

$ git clone path/to/repository

2.Using SSH:

To clone using SSH, type:

$ git clone username@host:path/to/repository


1.On GitHub, navigate to your fork of the repository you just forked.

2.In the right sidebar of your fork’s repository page, click the button with an arrow, below the “HTTP CLONE URL” to copy the clone URL for your fork.

3.Open Terminal (for Mac and Linux users) or the command line (for Windows users).

4.Type the following:

$ git clone https://github.com/YOUR-USERNAME/REPOSITORY-NAME

5.Press enter and your clone will be created. Now, you have a local copy of your fork of your repository!

When you fork a project in order to propose changes to the original repository, you can configure Git to pull changes from the original, or upstream, repository into the local clone of your fork.

How do you configure Git to sync your fork with the original repository?

1.Repeat the steps above to create a clone(as mentioned above^).

2.Change directories to the location of the fork you cloned in

3.Type the following: »$ git remote -v

4.Press Enter.

You’ll see the current configured remote repository for your fork.

5.Type : »$ git remote add upstream

Type the URL you copied and press Enter.

7.To verify the new upstream repository you’ve specified for your fork, type

git remote -v

again. You should see the URL for your fork as origin, and the URL for the original repository as upstream.

So now that’s done. What do you do next?


Branches allow you to build new features or test out ideas without putting your main project at risk.


If you are hoping to contribute back to the original repository, you can send a request to the original author to pull your fork into their repository by submitting a pull request.

Every public repository can be forked, so find a project you’re interested in and get forking!

Yayy,done!It may look a bit daunting in the beginning but once you get a hang of it, it gets really simple. GO AHEAD AND GIVE IT A TRY!

We recommend you install git, curl before you get started.

In Ubuntu

sudo apt-get install git curl


Make your current non-root user as a sudoer. To do so, write a file /etc/sudoers.d/USERNAME


Make it as only readable

$ chmod 0440 /etc/sudoers.d/USERNAME

NOTE Please avoid using superuser(root) from here. Run all the below commands as USERNAME

Install RVM

RVM is a command-line tool which allows you to easily install, manage, and work with multiple ruby environments from interpreters to sets of gems.

If your current .gnupg/ folder is in root permission, then change the permission to USERNAME with the command sudo chown -R USERNAME:USERNAME ~/.gnupg/

$ gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3

$ \curl -sSL -ip4 https://get.rvm.io | bash -s stable

to run rvm from anywhere

$ source ~/.rvm/scripts/rvm

Once you have rvm installed, go ahead and install ruby 2.2.2

$ rvm install ruby-2.2.2

This will download and install and setup ruby for ya. !

set the installed ruby as default

$ rvm use ruby-2.2.2 --default

Using Ruby

$ rvm list

rvm rubies

=\* ruby-2.2.2 [ x86_64 ]

=> - current
=* - current && default
 * - default  ``

Ruby on Rails

If you wish to work on a ruby on rails project like Nilavu

its quite simple.

$ git clone https://github.com/megamsys/nilavu.git

$ cd nilavu

$ bundle update

$ bundle install

$ rails s

Voila! we covered installing ruby and using it to run a RoR application.

You can use Megam - Cloud Management to launch a Ruby on Rails App in minutes..