Ruby gems that will enhance productivity as well as provide better functionality and design to your rails application. Believe me, after going through these gems, you will realize how awesome rails framework can be.
Twitter bootstrap is undoubtedly the most popular front-end framework to use for your website. It can easily give a smooth and professional look to any amateur looking website. It is easy to use too once your learn the syntax and conventions.
rails generate bootstrap:install -f
This will overwrite your application template to bootstrap style. It will also modify view generator templates to include bootstrap elements in scaffoldings’ views. For e.g. :
rails g scaffold User name:string email:string age:integer
Now go to http://localhost:3000/users. You will notice a clean, smooth, bootstrapped layout.
group :development do
gem 'binding of caller'
This is a must have gem if you work on rails. It replaces all the error pages that you encounter when browsing website in production mode. The new error pages are more detailed, have a cleaner interface and provides you with a working web console! Couldn’t have been more awesome.
Following are some of its features :
1. Call Stack trace
2. Shows data in the instance variables
3. Ruby Console have scope of the error block
Devise gem makes adding authentication system to your rails app, a cakewalk. Adapting the ‘convention over configuration’ philosophy of rails, the devise gem has got all the configurations of a typical authentication system ready for you. It provides you with quick starting generators, helpers and an easy to use API to create a secure login system for your app. For quickly creating a user login system, follow these commands:
rails generate devise:install
rails generate devise User
After that, restart your rails server. A basic user login system with default parameters is installed. Navigate to http://localhost:3000/users/sign_up to open the user sign up page. To sign in, open http://localhost:3000/users/sign_in. But still this authentication does not protect any controller or action. To add user authentication to any controller, add the following filter at the start of a controller.
To interact with the functionality of devise, some helpers are provided. Following method demonstrates the usage of these helpers:
u = User.find(current_user.id)
@email = u.email
user_session[:token] = generate_hash(u.email)
@notice = "Please log-in first"
Further information on this gem can be found here.
4. Will Paginate
This gem will add pagination to any model of your rails app in a few lines of code. This gem also provides view helpers that renders navigation links to different pages in HTML. You can then add CSS styling to these rendered links to match them with the styling of your website or to prettify them according to your needs.
For example, if you want to add pagination to your posts model, replace the active record statement in your controller with the following
@posts = Post.all.paginate(:page => params[:page], :per_page => 10)
And in your view, add the following to place the HTML code of page links
<%= will_paginate @posts %>
5. Thinking Sphinx
If your database is very large, performing even a simple text search can take a lot of time. Here, Sphinx comes to the rescue. To reduce search query timing, Sphinx performs indexing on the database, and serves this indexed database as a daemon on a network port (like MySql servers on port 3306). Thinking Sphinx gem provides an Active Record interface for this new indexed database, served by a Sphinx daemon.
I will be writing a separate tutorial on Sphinx soon. For more information about its usage, visit this link.
Recently graduated, majoring in Mathematics and Computing from IIT Kharagpur, Rohan is a technology enthusiast and passionate programmer. Likes to apply Mathematics and Artificial Intelligence to devise creative solutions to common problems.