Archive for category Ruby on Rails

Timestamps arent necessary

Whenever we create models in rails, we get a migration where timestamps are added to it. I accepted it as a rle of thumb till a day I was required to wrap my classes around a database in which the tab;es dd not have time stamp fields created_at and updated_at

Well then I tried the following piece of code rails g model tweet content:text and modified its migration so that it looks as floows

Look at it, it has no timestamps in it. I ran the migration and tried this code on the rails console

And it worked, proving Timestamps aren’t necessary. But its better to have them


, ,

1 Comment

Free ad space if you donate to RVM

Hello People,

I am very much fond of rvm . All the apps I have deployed runs on it. RVM needs funding so that it can be developed further. I want to hasten the process of funding.

I have written a ruby programming book named ‘I Love Ruby’ thats totally free, you can get it here (this book will be released on jan 2014 or earlier)

If you donate $2000 to RVM I will grant full page advertisement, half page for $1000 and quarter page ad for $500. If you have donated these amounts you can contact me on mindaslab at gmail dot com so that I can put your ad in it.

The advertisement will stay till Jan 31 2014. It must be designed by you.

Please donate to RVM by going to

, , , ,

Leave a comment

Very Simple Search for Active Records

Okay, you might encounter a need to put very simple search for active record / model in your Rails app and here is it. Put this code in your active record model:

Note this line

columns = [:name, :address, :city, :pin, :ph]

in the code snippet, give your own column names in that array.  This array can contain columns that are string and text type. Lets say you have put these stuff in a class called Person , to search it you need to issue a command like this "Karthik chennai"

This stuff works well with Sqlite, Postgre and MySQL. If you have tried this out with other DB, please add it in comments. Bye.

, , ,

Leave a comment

Planning for a Rails book

ror cover girl

Well, after the success of I Love Ruby( ), I am planning fora Rails book. You can see its cover above 😉

This book will be released under GNU free documentation license. Time will tell if this book will become a success.

, , , ,

1 Comment

Auto Routing In Rails 3

Long long ago,  one fine day I switched from Rails 2.x to Rails 3.x and I notices a thing like this, when you have a controller like this one

class UserController < ApplicationController

  def profile
    @title = "Your Links"
    @links = Kaminari.paginate_array(current_user.links | current_user.jeweled_links).page(params[:page]).per(20)

  def search
    @title = "Search for #{params[:s]}"
    @links = current_user.search_links(params[:s]).page(params[:page]).per(20)
    render :profile

and if you type http://localhost:3000/user/profile , you will get an error unless the route get ‘user/profile’ is added into routes.rb .
It might be frustrating for one to add hundreds of routes in a large project and quiet not so good looking to see a huge routes.rb file, so how to go about the Rails 2 way where you put an action in an controller you can simply access it?
Well its quiet simple, just launch your routes.rb file and find this line
match ':controller(/:action(/:id))(.:format)'

It would be commented out, so uncomment it. Now launch http://localhost:3000/user/profile in your browser and it will load!

, ,


Developing Large Scale Web Application (with Ruby on Rails)

My talk on Aprill 6th 2012 at Chennai.rb conference in System Insights, Chennai.

Leave a comment

rvm Gemsets

Lets say that you have two different Rails app. Now these apps would require certain types of gems, and some times these gem requirements could clash with each other. If that happens its better to use a thing called gem sets.

To know about gem sets take a look at this picture.


At the bottom you see the mighty rvm upon which can sit many Ruby installations, these installations can be switched using the rvm use <Ruby_version_number> , but lets say that you have two Ruby applications and for some strange reason you want to use one with older version of gems with one and another needs to use newer set of gems. You may want to  use different set of gems for an application, how to do that?

Well rvm has a thing called gemset with which you can group a set of gems under a name under a particular version of Ruby. This means as shown in the diagram above, note the green  boxes above Ruby 1.8 and 1.9 , you can have nnumber of gems ranginging from g1 to gn. You can name these gemsets any name you wish so that its quiet user friendly to change.

in the future if you think your Ruby / Rails / Sinatra or any other application is faltering due to  wrong gems installed, create a new gem set for it, switch it using rvm gemset commands and hope all things will go right. I am not going to dive deep into it as the rvm gemset has a good documentation here.

, , , , ,

Leave a comment

%d bloggers like this: