Upgrading Rails 2 Application to Rails 3.2

Hi guys,

If you have an Rails 2 application which you want to upgrade it to latest Rails version. Then here are the steps that would be useful for you.

Its not very easy to upgrade your Rails 2 application directly to Rails 3.2.x. Rails has been drastically undergone lots of changes till now. There are lots of major changes from Rails 2 to Rails 3. So before upgrading our application to the latest version of Rails first we will upgrade our Rails 2 application to Rails 3. 

Upgrading to Rails 3.0.0

First it would be great if you are using git. Create a new branch out of master. Lets name it rails3.

$ git checkout -b rails3

Run your spec to test to check all your tests are passing.

$ rake spec

This step is not mandatory. You can do it if you are very much worried about the tests. But lets don’t worry about this in first point. 

Nextly we have to update the Ruby version to 1.9.2 and install Rails 3. It would be better if you are using RVM. So install RVM if you don’t have and install Ruby 1.9.2.

$ rvm update
$ rvm reload
$ rvm install 1.9.2

After installing 1.9.2 you can tell the rvm to use ruby version 1.9.2

$ rvm use 1.9.2

You can check for Ruby version

$ ruby -v
ruby 1.9.2p318 (2012-02-14 revision 34678) [i686-linux]

Now intall Rails 3.0.0

$ gem install rails --version=3.0.0

Lets now start upgrading our application to Rails 3

First lets use a plugin known as rails_upgrade plugin that will help us to upgrade to Rails 3.

Before installing this plugin we have to switch back to our older Ruby version 1.8.7

$ rvm use system

We can now install the rails_upgrade plugin

$ script/plugin install git://github.com/rails/rails_upgrade.git

This will provide necessary documentation.

The first and the key command that this plugin provides is rails:upgrade:check.

$ rake rails:upgrade:check

The above command will show us the list of all files that needs to be updated with a proper message of what is to be updated in the files. The list may be huge. Before starting to update we need to take a backup of some of the key files that will be overwritten during the upgrade. To backup run the following command.

$ rake rails:upgrade:backup

Then we have to update each and every file. 

We will now start with upgrading to Rails 3. First switch back to latest Ruby version.

$ rvm use 1.9.2

Create a new Rails 3 application in current application directory as

$ rails new .

You can specify the database option along with creating the Rails application. For example if your application uses mysql then you can create the application as

$ rails new . -d mysql
$ bundle install

It will ask us for overwriting the existing files. We can do y/n option and if you are not sure then use option d to check the difference between the existing file and the one that will be overwritten.

We have just made backups of most of the important files in our application so we can choose to overwrite all of the conflicting files with the exception of the following:


Our application is upgraded to Rails 3.0 but we have to go through the backed up files and change the code that are specific to our application. We can note that the backed up files will have the extension .rails2. We have to open both backed up file and new file and copy any code that is necessary.

We can have a look at our routes file since the routing syntax have been changed in Rails3. The older routing may work in rails 3 but may show depreciation warnings. So better to change it to new syntax.

For example if you have a config/routes.rb file like

Railscasts::Application.routes.draw do |map|
    map.resources :companies
    map.resources :projects
    map.login 'login', :controller => 'sessions', :action => 'new'

Change it as follows

Railscasts::Application.routes.draw do
    resources :companies
    resources :projects
    get '/login' => "sessions#new", :as => "login"

Nextly we will have a look at config/environment.rb. We have to move the necessary configuration options to config/application.rb file. 

You can configure the session store in config/initializers/session_store.rb.

Then move the gems if you have any in environment.rb to Gemfile. For example if you have a gem will_paginate like

config.gem 'will_paginate'

then move the above code to Gemfile as

gem 'will_paginate'

And additionally if you are using rspec for tests you can add it to Gemfile.

group :development, :test do
    gem "rspec-rails", ">= 2.0.0.beta.19"

Note the change in syntax. After moving the gems to Gemfile do a bundle install to install the gems

$ bundle install

Addition to this there are certain other configurations. Uncomment and add the autoload path in config/application.rb

# Custom directories with classes and modules you want to be autoloadable.
config.autoload_paths += %W(#{Rails.root}/lib)

and add the following line before requiring rails/all in config/application.rb 

require File.expand_path('../boot', __FILE__)
require 'rails/all'

Now start the server

$ rails server

You may get some depreciation warnings. Make sure to fix all the warnings and start the server again and visit http://localhost:3000. We can see the default home page.

Remove the rails_upgrade plugin

$ rails plugin remove rails_upgrade_check

So we have successfully upgraded our application to Rails 3.0.0. Nextly we will upgrade Rails 3 application to Rails 3.1. 


Upgrading to Rails 3.1

First check whether you are running application with rails version 3.0.10. If not update it by setting the Rails version in Gemfile and do a bundle

gem "rails", "3.0.10"

We will start our upgrade to Rails 3.1 by creating a new branch

$ git checkout -b rails3.1

Open your Gemfile and update the rails version to 3.1.0 and do a bundle

gem "rails", "3.1.0"

We will now make the configuration changes. Open the file config/development.rb and comment the following line.

# config.action_view.debug_rjs = true

We can now start the server and check whether our application is running. 

Using Asset Pipeline in our application

Asset pipeline is one of the main feature of Rails 3.1. We can move our images. stylesheets and javascript files in public/ directory to assets directory.

Before doing it we have to enable this feature. First we need to add the following code to the Gemfile

# Gems used only for assets and not required
# in production environments by default.
group :assets do
    gem 'sass-rails', " ~> 3.1.0"
    gem 'coffee-rails', " ~> 3.1.0"
    gem 'uglifier'

gem 'jquery-rails'

This code creates an assets group and puts some asset-related gems in it. It also includes the jquery-rails gem so that we can use jQuery. 

We will then modify our config/application.rb file. Replace the following code

# If you have a Gemfile, require the gems listed there, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env) if defined?(Bundler)

with the code below

if defined?(Bundler)
  # If you precompile assets before deploying to production, use this line
  Bundler.require *Rails.groups(:assets => %w(development test))
  # If you want your assets lazily compiled in production, use this line
  # Bundler.require(:default, :assets, Rails.env)

This code adds the assets group to the groups that are required by Bundler. We then need to enable the asset pipeline by adding the following lines to config/application.rb file.

# Enable the asset pipeline
config.assets.enabled = true
# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'

Then we have to change the settings in environment configuration files. Open config/environments/development.rb and add the following lines.

# Do not compress assets
config.assets.compress = false
# Expands the lines which load the assets
config.assets.debug = true

Nextly add the following settings to config/environments/production.rb file

# Compress JavaScript and CSS
config.assets.compress = true

# Don't fallback to assets pipeline
config.assets.compile = false

# Generate digests for assets URLs
config.assets.digest = true

Lastly we’ll modify the test environment. Here we add options so that static assets are served and cached and we also enable asset debugging. Open config/environments/test.rb and add the below code.

# Configure static asset server for tests with Cache-Control for performance
config.serve_static_assets = true
config.static_cache_control = "public, max-age=3600"

# Allow pass debug_assets=true as a query parameter to load pages with unpackaged assets
config.assets.allow_debugging = true

If we’re using Git for our application’s source control we should also modify the .gitignore file and add the .sass-cache directory to the list of ignored items.


Moving the Assets

Now that we have enabled the asset pipeline and added necessary settings, we can now move our images, stylesheets and javascript files from public/ directory to app/assets/ directory

$ mkdir app/assets
$ mv public/images/ app/assets/images/
$ mv public/javascripts/ app/assets/javascripts/
$ mv public/stylesheets/ app/assets/stylesheets/

Some of the files we’ve moved aren’t needed anymore, such as the jQuery-related files in the javascripts directory. These are included in the jQuery gem and so we can remove jquery.js, jquery.min.js, and rails.js. 

Create Manifest Files

Create the files app/assets/stylesheets/application.css and app/assets/javascripts/application.js if not present in your application. To turn these files into a manifest file we need to add some comments at the top that will tell Sprockets which files to include.


*= require_self
*= require_tree .
/* rest of file omitted */


//= require jquery
//= require jquery_ujs
//= require_self
//= require_tree .
/* rest of file omitted */

We’ll also need to go into the application’s layout file and change the lines that include the stylesheets and JavaScript files.


<%= stylesheet_link_tag "application" %>
<%= javascript_include_tag "application" %>

So finally everything is done and we can now start our server and check if everything works file

$ rails server

You have to notice one thing that if you are using any images in your application then you should change the source path of the image as /assets/logo.png instead of /images/logo.png since we have moved the images from public/ directiory to app/assets/ directory.

We have done with upgrading our application to Rails 3.1. 


Upgrading to Rails 3.2

Since we have upgraded our application to Rails 3.1, upgrading it to Rails 3.2 is very simple. Create a new branch before upgrading like

$ git checkout -b rails3.2

First open the Gemfile and change the version of gems like mentioned below.

source 'http://rubygems.org'

gem 'rails', '3.2.0'

# Gems used only for assets and not required
# in production environments by default.
group :assets do
    gem 'sass-rails', " ~> 3.2.3"
    gem 'coffee-rails', "~> 3.2.1"
    gem 'uglifier', '>=1.0.3'

gem 'jquery-rails'
$ bundle install

We have now updated the Rails version to 3.2. Now we will add some addition environment configuration for Rails 3.2.

Add the following lines to /config/environments/development.rb and /config/environments/test.rb files

# Raise exception on mass assignment protection for Active Record models
config.active_record.mass_assignment_sanitizer = :strict

# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
config.active_record.auto_explain_threshold_in_seconds = 0.5

The first of these sets mass_assignment_sanitizer to :strict which will raise an exception if the mass assignment goes against the protection.

Remove the following line from /config/environments/test.rb file

# Allow pass debug_assets=true as a query parameter to load pages with unpackaged assets
config.assets.allow_debugging = true

We have done with the configuration settings. We can now test our application by running the server and check everything works fine.

$ rails server

So finally we have upgraded our application from Rails 2.0.x to Rails 3.2.x.:-)

Hope you find the above post useful.:-) 



Posted in Uncategorized | 2 Comments

Presented a stall on Ruby at Software Freedom Day 2012


This year Software Freedom Day was held at D.G.Vaishnav College, Arumbakkam Chennai on 15 Sep 2012. This is the first time I was participating as well as volunteering for SFD. In this post I share about my experience about SFD.

About SFD :

Software Freedom Day is an event which is conducted every year all over the world in the month of September which focuses on creating awareness about GNU/Linux and spreading the open source software to the people.

In Chennai SFD was organized on behalf of Indian Linux User Group (ILUGC) and Free Software Foundation Tamil Nadu (FSFTN).


Presented a stall on Ruby:

In this SFD,  I presented a stall on “Ruby” (http://www.ruby-lang.org/en/). Ruby is an open source, dynamic and very simple programming language. I just gave an introduction to Ruby with simple examples to the visitors. I didn’t actually prepare anything for SFD. I decided to present a stall on Ruby the day before the event. I would like to thank T.ARULALAN, my friend, for providing me a short presentation about Ruby. I also thank SATISH, my MCA junior, who accompanied me in presenting the stall on Ruby.

Students from D.G. Vaishnav college and other college students visited our stall and most of them where interested to start learning Ruby. Students where from both IT and Non-IT departments. Even some professors visited our stall. We felt very happy in presenting a stall on Ruby.


Other Stalls:

There were other stalls like

  • Screencasting
  • Android Application Development
  • Mozilla Suites and development
  • Geany IDE
  • Bluefish IDE
  • Open Source Databases – MySQL/PostgreSQL
  • Open Source Virualization Tools
  • Mysql Bench
  • Subversion Edge – Version Control System
  • wikipedia
  • MongoDB – NoSQL Database
  • etc…

and much more. There were nearly 30 stalls on various open source tools presented in SFD.


Tech Talks:

Apart from stalls there were tech talks given by Raman, Welkin, Yogesh, Atul jha, Kingsly, Balachandar, Subramani in the class room and in the



Free stickers and pamphlets was provided to the stall members and visitors.

Finally the event was great success since this time there were many visitors participated in SFD. Shrinivasan (coordinator of ILUGC) gave gifts to stall members. I was personally very happy in being a part of this great event and it was really a great experience.


SFD in Media:

The SFD event was covered in Deccan Chronicle. Here is the link - http://www.deccanchronicle.com/channels/cities/chennai/free-software-day-woos-youngsters-226

SFD snaps:

Here are some of the snaps of SFD



On the whole the event was great and I had a wonderful experience in participating in SFD. I hope that I will also participate in other open source events in future.:)



Posted in Uncategorized | Leave a comment

2011 in review

The WordPress.com stats helper monkeys prepared a 2011 annual report for this blog.

Here’s an excerpt:

A New York City subway train holds 1,200 people. This blog was viewed about 7,000 times in 2011. If it were a NYC subway train, it would take about 6 trips to carry that many people.

Click here to see the complete report.

Posted in Uncategorized | 4 Comments

A Simple Birthday Remainder Application Using Ruby


One of my friend Arulalan had developed an wonderful Birthday Remainder application in Ruby some years back. It is really an cool application which reminds you of our friends birthday when we log into our system.

Arulalan had published a blog about this application. Here is the reference link.


I tried to use that application in ubuntu 8.04. But it was not working. After that I tried to use that application in Ubuntu 9.10. In this version also it was not working. I dont know why it was not working. At that time I dont know much about Ruby. So I could not able to debug and find the issue. I just left after that.

Now I learnt Ruby and completely working on Ruby. Suddenly that application came to my mind some time back and thought why can’t I debug the application now and make it work. I asked Arul about where he is having the code so that I can debug it. Then he gave his blog reference and I tried to find the issue and fix it.

There was not a very big issue with the code. There were some simple syntax problem since I took the code from the blog. And the date and time functions he used in his code where deprecated in the newer version of Ruby. I fixed the issue and now it is working fine. I also optimised the code.


Birthday Remainder Code: birthday.rb

#!/usr/bin/env ruby
require 'rubygems'
db_file_path = File.expand_path(File.join(File.dirname(__FILE__),"../birthday_remainder/database"))
file = File.open(db_file_path ,'r')
file.each do |bday|
  bday = bday.chomp!
  bday = bday.split(",")
  name = bday[0].to_s
  dob = bday[1].to_s
  image_path = bday[2].to_s
  if image_path == "default"
    image_path = "~/birthday_remainder/cake.jpg"
  today = Time.now.strftime("%d-%m")
  tomorrow = (Time.now + (24*60*60)).strftime("%d-%m")
  if today == dob
    system("notify-send 'Birthday Remainder' 'Today is #{name} Birthday' -i #{image_path} -t 3000")
    system("notify-send 'BirthDay Remainder' 'Did U wished #{name} Birthday ?' -t 0")
  if tomorrow == dob
    system("notify-send 'Birthday Remainder' 'Tomorrow is #{name} Birthday' -i #{image_path} -t 3000")
    system("notify-send 'BirthDay Remainder' 'Did U Purchased Gift For #{name} Birthday ?' -t 0")

The above code will remind todays and tomorrows birthday.


Procedure for using this application

The procedure for using this application is already given in Arul blog.


To use this application just follow the steps below.

Step 1: First we need to install the following:

$ sudo apt-get install libnotify-bin

$ sudo apt-get install ruby

$ sudo apt-get install rubygems


Step 2:

1. Create a folder birthday_remainder in your Home folder.

2. Put the file birthday.rb and your friends photos in this folder.

3. Create another file database in this folder.


In this file you have to give your friends birthday in the following format.

Format: name,dateofbirth,image_path

Example : Arulalan,21-08,~/birthday_remainder/ramachandran.jpg

You have to notice that the date of birth format. It is day and month separated by (-) symbol. Both day(1-31) and month(1-12) should be given in double digit.

The image path can be any path. If you dont have your friends photo you can just have an image of an cake with name “cake.jpeg” in the birthday_remainder folder and specify the path as default. It will automatically take the image path of the cake image.

Example : Ramachandran,22-08,default


Step 3 : Change the permission of birthday_remainder folder as

$ sudo chmod -R 777 ~/birthday_remainder


Step 4 : Add this application as startup application

1. Go to Sytem -> Preferences -> Startup Applications

2. Click on Add button.

3. In the dialog give the name as “Birthday Remainder”.

4. In the command field browse the birthday.rb file from Home -> birthday_remainder -> birthday.rb

5. Give some description about this application in Comment field.

6. Then click on Add button.

Thats all. Now this application is added as startup application. It will remind your friends birthday when you log into your system.


You can check this by giving a sample date of birth as current date in database file in the format mentioned earlier.

Example : database



Then logout or restart the system. The application will show the remainder in the desktop.



Wow. Isn’t that cool. Just try this application in your system.




Posted in Uncategorized | 1 Comment

Attended RubyConf INDIA 2011


This year RubyConf was held on 28th and 29th May 2011 at Royal Orchid Hotel, Bangalore. ThoughtWorks was the Platinum sponsors of this great event.

I felt very great to be a part of RubyConf 2011. This is the first time I attending RubyConf. Myself with the team from Artha42 Innovations Private Limited attended this event.

We all started from Chennai on 27th May, got the train by 11 PM in the central railway station and we reached Bangalore in the morning on 28th May. Wow Bangalore was really nice city. This was the first time I went to Bangalore. We refreshed ourselves in a hotel. Then we booked a cab to reach Royal Orchid. On the way we had our breakfast and  we reached the hotel Royal Orchid around 9 PM. We all registered and got the RubyConf 2011 kit. The event started by 10 AM.

DAY 1 – 28th May 2011

First Rohit Bansal who is the Head of Social Impact of ThoughtWorks welcomed everyone and gave a kick-off session. Then the talk of the speakers started by 10:15.

Session 1: Building Rails apps for the rich client

Speaker : Yehuda Katz

Yehuda Katz is as member of the SproutCore. He is the co-author of the best-selling ‘jQuery in Action“, the upcoming “Rails 3 in  Action”, and a contributor to “Ruby in Practice“.

Katz gave a opening keynote on Building Rails app for the rich client. He explained the feature of the Rails and advantages. He a brief talk on the topics like:

  • Rails Rich HTTP Abstraction
  • Fat Modle and Skinny Controllers
  • ActiveRecord
  • Token Authenticable
  • Action Dispatch
  • Middleware
  • Sessions
  • Standards
  • Cookies
  • Parameters
  • Reloading
  • Security
  • Routing
  • Constraints
  • Optional segment
  • Caching
  • Action Mailers
He also explained the Rich client MVC architecture. Then He explained about the API
  • ActiveRecord

He then explained the rules of good API design

His talk was really very interesting.


Session 2 :

This session was a video keynote of Yukihiro Matsumoto. Matz was the founder of Ruby. He talked about the evolution of Ruby over the years. He also insisted the Ruby developers to be good since Ruby is good and of course he is also good.:)


Tea Break:

We had a tea break where we got a chance to meet other professionals and geeks from different regions and had a chat with them. I also took a snap with Matz. Cool.


Session 3 : Single page web apps with Backbone.js and Ruby on Rails

Speaker : Prateek Mohan Dayal from SupportBee.com

Prateek gave a introduction to Backbone.js. Backbone.js is a new technology for me to know. The speaker explained the MVC pattern in Backbone.js.

  • M – Model
  • V – View
  • C – Collections

He explained how Backbone.js can be used with Rails. He also explained how Backbone.js works with some code examples. It was nice talk.


Lunch Break:

We had our lunch break from 12:30 – 1: 30. We had a very nice lunch and also get introduced to some geeks.


Session 4 : Deciphering the Ruby Object Model

Speaker : Karthik – Application developer at ThoughtWorks India.

Karthik first gave a introduction to Ruby object model and he explained the Axiom of the object model with a diagram.

He explained about:

  • Classes
  • Class variables
  • Class instance variable
  • Access modifiers
  • Singleton methods – A method defined to be specific to a single object
  • Module
The talk was also good.


Session 5 : Make your own Rails framework

Speaker : Pankaj Bhageria – Tech lead in Sumeru Software Solutions

Pankaj explained how to make our own Rails framework. He started explaining about the Rack. Then he explained the steps involved in building a framework. He insisted everyone to take initiative and build their own framework. His talk was very inspiring and useful.


Session 6 : Writing compilers the easy way

Speaker : Vishnu Gopal – CTO of MobME Wireless Solutions Pvt. Ltd.

Vishnu started with explaining compilers and parsers. He explained about the Treetop which is a parser library for Ruby. He described how a compiler works. He showed some code examples of writing a simple compiler. The talk was very interesting and useful.


Session : 7

At the end of the day the final session was a video keynote of Chad Fowler. Chad Fowler described about the Service.

All the talks on first day was very interesting and I learnt many things.


DAY 2 – 29th May 2011

The next day we reached the hotel ROYAL ORCHID around 9:30 AM. The session started by 10 AM.

Session 1 : The good, the bad and the ugly

Speaker : Ola Bini 

Ola Bini works as a language geek for ThoughtWorks in Chicago. He is one of the core developers of JRuby.

Ola Bini started with the evolution of Ruby and its versions from the beginning. The he described the the bad, the ugly and good things in Ruby programming.

The Bad things in Ruby programming are:

  • The FlipFlop operator
  • $ and @ operators
  • Warn
  • Bindings
  • defined?
The Ugly things in Ruby programming are:
  • Return values
  • Speed
  • Blocks
  • Exception
  • Keyword arguments
  • Module inclusion

The Good things in Ruby programming are:

  • Monkey patching
  • Refinement
  • Namespace
  • Meta-programming
  • Syntax
  • Regular expressions
  • Syntax
  • Taint
  • Memory management
  • Agent
  • Thread

Ola Bini explained most of the above with code examples. His talk was interesting and useful.


Session 2 : Let’ Have a cup of CoffeeScript

Speaker : Nicolas Sanguinetti

Nicolas gave a introduction about CoffeeScript. He explained how CoffeeScript helps us to write better JavaScript. He showed us various code examples to understand the CoffeeScript.

He explained about the basic syntax and simple code examples and explained us about

  • Existential operator ( expr? )
  • Patterns
  • Comprehensions

The whole session was very interesting. I learnt some basic things in CoffeeScript.


Session 3 : Continuous Delivery in Ruby

Speakers : Srushti Ambekallu & Brian Guthrie

The session was a interaction session with the speakers. They discussed about continuous delivery in Ruby. They discussed how we can deliver the product with better quality and within a short period of time. They discussed about

  • Unit and Regression tests
  • Automated and Acceptance tests
  • User Acceptance tests
  • Automating the deployment process
  • RVM – should not be used for production

The discussion was very funny and quiet interesting.


Session 4 : But the language supports it

Speakers : Niranjan Paranjape & Aakash Dharmadhikari

In this session the speakers explained about the features in language that we use because the language supports it. They explained about

  • GOTO statement
  • Switch
  • Hash
  • Raise
  • Rescue
  • Private methods


Session 5 : Designing high throughput web service clients

Speaker : Sherin C – Engineering lead at MobME Wireless Solutions


Session 6 : Memory is the new disk, say hello to Redis

Speaker : Bratish Goswami – Senior software engineer at Castle Rock Research, Kolkata

Bratish first gave a brief introduction about Redis.

Redis – Collection of data structures exposed over the network.

The data are stored in our disk rather than storing it in any database.

He explained the features and advantages of using Redis.

  • Memcached with simplicity
  • More datatypes
  • More commands
  • Persistance with non-blocking I/O
  • Publish subscribe channel

Installation :

He then explained how to install Redis

Version -> 2.2.8

$ clone https://github.com/antirez/redis.git

Datatypes in Redis

  • Strings
  • Lists
  • Sets
  • Sorted sets
  • Hashes

He explained about all the datatypes in detail. He also explained the keys and persistence of Redis. He gave a detailed description of Redis with demo. The session was also interesting.


Final Session : Happiness : Ruby : : Freedom : JRuby

Speaker : Nick Sieger

This session was the final keynote by Nick. He described about the Ruby and JRuby features.


Finally all the sessions were over by 5:30 PM. This day also we met some of the geeks and had some chat with them during Tea and Lunch breaks and shared our experience.

All the sessions were interesting. It was a great opportunity to learn many technologies and meet various geeks. It was a great experience attending RubyConf 2011. I thank ThoughtWorks for organizing such a great event and also thank other sponsors.

We left from Royal Orchid Hotel by 6 PM. Myself with my colleagues went roaming around the Bangalore city for some time since our train timing is 11:15 PM. Since Bangalore was new to me I had to good time there. Climate was really good.

We had our dinner in a hotel and reached the station by 10 PM. We got train by 11:15 PM and reached Chennai in the morning around 7 – 7:30. The train was too late.

I thank the management of Artha42 Innovation Pvt Ltd. for giving the opportunity to be a part of RubyConf 2011.

I really had a good experience visiting Bangalore and attending RubyConf. Hope will attend RubyConf every year.



Posted in Uncategorized | Leave a comment

Carrierwave Gem in Rails


Carrierwave gem provides a flexible way to upload files from our Ruby applications. It is similar to paperclip gem in Rails 2.

Installing Carrierwave

We can install carrierwave gem using the following command.

$ gem  install  carrierwave

In our Rails application open the Gemfile and add the line

$ vi  Gemfile
gem  'carrierwave'

Using carrierwave


Create a Rails application where an candidate is applying for an job application.

$ rails new job_application
$ cd job_application
$ rails generate resource candidate name:string email:string phone:string skills:string qualification:string
$ rake db:migrate

We are now going to provide the candidate with option to upload the resume.

$ rails  generate  uploader  Resume

The above command will create a file resume_uploader.rb in app/uploaders/

In this file we can see something like below


class ResumeUploader < CarrierWave::Uploader::Base

storage :file


Add a string coloumn to the model where we want the uploader

t.string :resume

After adding this coloumn in migration drop and migrate the database.

Now mount the uploader in the model file.

class Candidate < ActiveRecord::Base

  mount_uploader :resume, ResumeUploader


In the form dont forget to set the html mutipart option to true for uploading the resume.

Now everything is done. We can now upload the resume.



Restricting User to upload only specified types of files

There is one more interesting option is there in carrierwave. We can restrict the type of the file to be uploaded.

Open the file app/uploaders/resume_uploader.rb

def extension_white_list
  %w(doc docx pdf odt)

We can provide the set of file types that can be uploaded. If the user tries to upload any file apart from what is provided in the extension white list method, then the carrierwave will not upload the file and it throws an error to the user.



The above is the simple example of how we can use carrierwave for uploading documents. I hope you found the above example useful for getting started and working with carrierwave.

For more information you can look at the following github documentation - https://github.com/jnicklas/carrierwave



Posted in Uncategorized | 4 Comments

Participated in Chennai Java Summit 2011


I participated in the Java Summit event on 16-4-2011(Saturday). This is a two days event organized by Java User Group Chennai(JUGC) and this is the first event of JUGC. The event took place at Tenth Planet Technologies located at Anna Salai (opposite to LIC).

In this event there where many talks on various interesting topics by various speakers. The below are all the topics on which talks was given on first day of the event.

  • NoSQL          -            Speaker : Mani Duraisamy (CTO of OrangeScape)
  • Mirah           –            Speaker : A.Senthil Nayagam                                                                                                                  (Co-Founder and CEO of RailsFactory)
  • JRuby           –            Speaker : Vagmi Mudumbai                                                                                                                     (Founder and CTO of Artha42 Innovations)
  • WeaverFX    -           Speaker : Veerendra Nagabhirava
                                                         (Founder and creator of WeaverFx)
  • Managing Software Development using BDD and TDD

                Speakers :

  1. Rajesh S (Delivery Manager at CoreObjects)
  2.  Venkatesh S (Technical enthusiast and contributor for opensource projects)

All the topics where very interesting and useful. I learnt some JVM languages like Mirah, JRuby etc and other technologies. This is the first time I am attending the JUGC event and I was very happy to be part of this great event. I wish and expect JUGC to organize many events like this in the future.



Posted in Uncategorized | 1 Comment