Ruby on Rails application Deploying in Heroku

Deploying ROR application in heroku is not a rocket science  now but some developer is having some confusion with this thing so only this blog post , So this post not for experienced developers 🙂

The first thing you need to understand heroku uses git for deployment , so that you need to have git repository in your ROR application first .

Then you need to install heroku toolbelt go here to get tool-belt for your OS , then install heroku gem

gem install heroku

If you don’t have heroku account create one, then on your terminal type

heroku login

It will asks your credentials give them, then go to your application directory by terminal and type

heroku create optional-app-name

If you give application name it will create DNS same like that otherwise it will generate one for you.Then type

git push heroku master

It will push your code to heroku , It uses SSH to access , This is first time in your system to connect with heroku and using SSH means , type

ssh-keygen -t rsa

heroku keys:add

note: Heroku uses pg as default data base, so please ensure you have included gem ‘pg’ in your gem file.

If you have any problem with ssh see


Multiple model search in rails with solr

lrSearching is much easier if you use solr or elastic search, no need to write complex database queries.

If you want to integrate solr with your rails application means there is a gem available

Add to Gemfile:

gem 'sunspot_rails'
gem 'sunspot_solr' # optional pre-packaged Solr distribution for use in development

Bundle it!

bundle install

Generate a default configuration file:

rails generate sunspot_rails:install

If sunspot_solr was installed, start the packaged Solr distribution with:

 bundle exec rake sunspot:solr:start

Then add the following code in model file which you going to search

searchable do
  text :<field_name>

In your controller queries

@search = Project.solr_search do
fulltext params[:search]
@projects = @search.results

Thats all, if you pass search params from your view file, then solr will give you the relevant projects.

Now I will show you how to search multi models in same querie,

simply add the same

searchable do
 text :<field_name>

In model files which you need to search, Then in your controller

@search =,Comment, File) do |s|

@result = @search.result

will give you the result from project, file and comment models

Easy Ruby on Rails install

Whenever I setup new Linux for developing rails application. I feel bit tired of installing all necessary things for rails development.

For that I have written one shell script, that install most of the things requires for rails development. If you want this lazy thing. You can check here

And use it , fork the code and update if you feel some thing to be added.


A simple instruction to Rspec – 3 in Ruby on Rails -4

This is small introduction about rspec version 3 for ruby on rails developers, and also note that this is not mean for techy geeks 🙂

Initial Setup
add gem 'rspec-rails', '~> 3.0.0'

then bundle install

And run rails generator rspec:install

Herein after spec files are automatically created when ever you create model, controller, view files, if you dont want any spec file to be created automatically then
in your application.rb

config.generators do |g|
g.test_framework :rspec,
view_specs: false,
helper_specs: false,
routing_specs: false,
controller_specs: true,
request_specs: false

put false wherever you dont want to create spec files
RSpec generators can also be run independently. For instance,

rails generate rspec:model post

All specs are created inside spec folder and to run test just type rspec in terminal

If you want to test only a particular file say products.rb in model then

 rspec ../rails_app/spec/models/products.rb

Thats all

Model specs

require "rails_helper"

describe Post do
it “checks it saves the data” do
expect(Post.count).to eq 0
expect(Post.count).to eq 1

controller spec

require 'rails_helper'

RSpec.describe WelcomeController, :type => :controller do
it ‘has 300 status code’ do
get :index
expect(response.status).to eq(200)


rspec-rails offers a number of custom matchers, most of which are
rspec-compatible wrappers for Rails’ assertions.

expect(response).to redirect_to(path)
expect(response).to render_template(template_name)
assigned objects
expect(assigns(:widget)).to be_a_new(Widget)

Easy way to deploy Rails 4 application in Unicorn with Nginx

In this post I will show you how to host our rails application with unicorn and nginx

The first step is obviously to install nginx for that go to your control terminal then type

sudo apt-get install “nginx”

After the installation go to /etc/nginx/sites_enabled/ – (or wherever you installed nginx)

in this sites_enabled folder you have default.conf file delete that file and create new file called nginx.conf

listen 80 default;
root /home/ideology/test_server_nginx/public;
try_files $uri/index.html $uri @unicorn;
location @unicorn {
proxy_pass http://localhost:3000;

error_page 500 501 502 503 /404.html;

save the file with above code

Now In your rails application folder gemfile.rb add gem “unicorn” and run bundle install

Then start your rails application with unicorn with port 3000

    /application_folder/unicorn -p 3000

Then you can seen your application in browser with nginx server at port 80

Thats all! very simple yes?……

To change environment to production

RAILS_ENV=production rake db:migrate

and then in your boot.rb file add this lines

require ‘securerandom’
ENV[‘SECRET_KEY_BASE’] = SecureRandom.hex

then start your rails application unicorn server

RAILS_ENV=production unicorn -p 3000

And thats all your environment is changed to production now ,

But this is just a fast start up only this is not the correct solution to host your application you need additionally unicorn configuration files for further reference

Gemmified version of jquery plug-in stick

Sticky is a jQuery plugin that gives you the ability to make any element on your page always stay visible .This is gemmified version of sticky

jQuery sticky 1.0.0 –


Add this line to your application’s Gemfile:

gem 'sticky-rails'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install sticky-rails


Sticky is a jQuery plugin that gives you the ability to make any element on your page always stay visible. , so please check if you are using the jquery on your rails app

//= require jquery

Your app/assets/javascripts/application.js must appear like:

//= require jquery
//= require jquery_ujs
//= require jquery.sticky.js
//= require_tree .

Basic Structure example from



If you are going to use coffee script:

$(document).ready ->

Or just javascript:


For more documentation please checkout the sticky-rails 4 repository here:

Gem Author