Awesome print @console

Pretty print your Ruby objects with style — in full color and with proper indentation

Git source: Installing as Ruby gem
$ gem install awesome_print

# Cloning the repository
$ git clone git://

rails console ex: ap User(console)
<%= ap %> (HTML)

To list database tables/objects using the Rails console
$irb: ActiveRecord::Base.connection.tables


Cron job


The format for cronjobs is:

+—————- minute (0 – 59)
| +————- hour (0 – 23)
| | +———- day of month (1 – 31)
| | | +——- month (1 – 12)
| | | | +—- day of week (0 – 6) (Sunday=0 or 7)
| | | | |
* * * * * command to be executed


To have a cron executed on Sunday you can use either of these:

5 8 * * 0
5 8 * * 7
5 8 * * Sun
Where 5 8 stands for the time of the day when this will happen: 8:05.

You can always use as a editor to check your cron expressions.

Running a .rb file from IRB

You can “run” a file in irb by just requiring or loading it.

$ irb
>> load './filename.rb'

To change your current working directory within irb, you can use FileUtils:

>> require 'fileutils'
>> FileUtils.pwd # prints working directory
>> '/path/to/somewhere' # changes the directory

RESTful Architecture

RESTful interface means clean URLs, less code, CRUD interface.


HTTP verbs: GET, POST. In REST, they add 2 new verbs, i.e, PUT, DELETE.

GET : Retrieve data from database.

POST : Create new record in database.

PUT : Updating any existing record in database

DELETE : Destroying any record in database.

7 Default Actions          REST Verbs

index                                   GET

show                                    GET

new                                      GET

create                                  POST

edit                                       GET

update                                 PUT

destroy                                DELETE

Simple queries

$ client = Client.find(10)   $ SELECT * FROM clients WHERE ( = 10) LIMIT 1

# => #<Client id: 10, first_name: “Ryan”>


# Find the clients with primary keys 1 and 10.

$ client = Client.find([1, 10])  $ SELECT * FROM clients WHERE ( IN (1,10))


The take method retrieves a record without any implicit ordering

$ client = Client.take    $ SELECT * FROM clients LIMIT 1

# => #<Client id: 1, first_name: “Lifo”>

$ client = Client.take(2)

# => [

#   #<Client id: 1, first_name: “Lifo”>,

#   #<Client id: 220, first_name: “Sara”>

# ]


Client = Client.first  $SELECT * FROM clients ORDER BY ASC LIMIT 1

client = Client.first(3)

# => [

#   #<Client id: 1, first_name: “Lifo”>,

#   #<Client id: 2, first_name: “Fifo”>,

#   #<Client id: 3, first_name: “Filo”>

# ]


Client.where(first_name: ‘Lifo’).take

Same as:

Client.find_by first_name: ‘Lifo’

# => #<Client id: 1, first_name: “Lifo”>






PostgreSQL Basic commands

login: $ psql -d database_name -U user_Name

List all the tables: $ \dt

Describe a table:$ \d table_name

connect to new db : $ \c DB_NAME

size of db:\l+ db_name   or

select pg_size_pretty(pg_database_size(‘DB_NAME’));

Quit: $ \q

Running ‘rake assets:precompile’ in dev mode makes Rails include code twice

# Put this at the end of your config/routes.rb
if Rails.env.development?
  app =
    lambda{ |env| [404, { 'X-Cascade' => 'pass'}, []] },

  mount app, :at => '/', :as => :public
More details @

25+ Ruby on Rails Gems For Rapid Prototyping

Web development is one of the very few domains that require constant learning. Trends and technologies pop up in no time and in many instances, they go bust in the blink of an eye as well. Still, there are some web technologies and frameworks that have successfully passed the test of time with flying colors. Ruby on Rails is one splendid example.

Rails took what was an obscure language without much of a traction mainstream. Since then, a vocal and highly enthusiastic community has nurtured it with extensive documentation and ruby gems to extend the functionality of the core Rails framework. After the break, let us take a look at ruby gems that can help you put together a Rails powered web app in short order.

Administration Panel

It’s hard to find web apps that don’t require an administration panel. There are a few ruby gems that offer admin interface functionality out of the box and Active Admin is one among them. The success of Active Admin is primarily credited to creating not just functional admin interfaces, but highly stylish ones at that. Comprehensive documentation works in favor of it too.

If you are looking for something more than an admin panel, try Hobo. It’s a super framework of sorts that’s capable of creating everything from a functional backend to subsites and permission systems. Doesn’t work with all versions of Rails though!


Creating forms using Rails is a piece of cake. However, if your intention is to create beautiful, semantically rich and styleable forms go with Formtastic. SimpleForm is a compelling choice too!


You could spend few hours writing code to check if users are who they say they are, or use a gem like Devise or Authlogic. Devise does a lot of heavy lifting for you and creates the respective models, views and controllers as well. For a change, are you searching for a way to allow users to sign in with their Facebook, Twitter or OpenID accounts? OmniAuth is what you are looking for.


Restricting users from accessing certain features of the app is key if you have a tiered subscription model. Gems like CanCan and canard take the pain out of the process. CanCan is simpler to use and the fact that it’s maintained by the legendary Ryan Bates makes it a perfect choice.

Background Jobs

The built in email handling capabilities of Rails are good enough in most cases. Except when queuing mails to be sent later. ResqueMailer allows messages prepared by ActionMailer to be delivered asynchronously. With this gem installed, the user don’t have to sit around waiting for the email to be sent out before proceeding further.

It’s just not sending emails that could be executed in the background. Use gems like Resque,Foreman and Delayed Job, for creating background jobs, placing them on multiple queues, and processing them later.


I’m not even going to mention an alternative gem for this category. From responsive grids to buttons and javascript powered sliders, Twitter Bootstrap is a production ready package.Twitter Bootstrap for Rails gem integrates Bootstrap CSS toolkit for Rails 3.1 Asset Pipeline, making things easy for you.


Rails is pretty much locked down and common attacks like cross site scripting cannot happen with a web app built using RoR. There are a tons of gems out there to secure your web app and the one we highly recommend is Brakeman. It’s a static analysis tool which checks Rails applications for security vulnerabilities. This gem finds security issues at any stage of development and I suggest you install it ASAP.


It’s true that testing saves your bacon and there is a bouquet of ruby gems readily available to test your app any which way you want. Cucumber and RSpec come highly recommended and they both have loads of documentation to get you started quickly.


Now that you have developed and tested the app, it’s time to move the code to production. Popular Rails app hosters Heroku and Engineyard have gems of their own to facilitate the process. But, if your choice is an economical VPS or AWS, try Phusion Passenger orCapistrano.


It’s only natural for developers to offer an API so that other curious souls can leverage it to create cool mashups. RABL and Grape are two fantastic API builder frameworks widely used by the Rails community.

Moving beyond the core web app components, there are a variety of gems that help you tackle project specific requirements. For instance, you can link the web app to a CMS using Refineryor an online storefront using Spree. Dalli assists in high performance caching, Prawngenerates dynamite PDF files and Paperclip excels in file attachment management.

I could go on and on, the list is endless! If I missed cool gems off the list, leave a comment and I’ll add it to the list. Trying to gather information from all around.