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.

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"
end

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'
end
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)
end

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.

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.

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.

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
auditorium.

———————————————————————————————————-

Goodies:

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.

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.

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

Arulalan,21-08,~/birthday_remainder/Arulalan.jpg

Ramachandran,22-08,default

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

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

MIMES

Action Mailers

He also explained the Rich client MVC architecture. Then He explained about the API

ActiveRecord

JSON API

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

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.

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.

Screenshots:

——————————————————————————————————————————-

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)
end

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.

Screenshot:

——————————————————————————————————————————-

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.

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.

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.