Monday, March 28, 2011

Weekly Diary of a Rails Developer

Day 1
Ruby on Rails Installtion

Rails installation and configuration
Installing rvm for ruby versions on same system.
Installing dependencies for rails,rvm and gems like iconv,mysql,hpricot,sqlite,nokogiri etc by using apt-get.
Solving issues found during installation.


Day 2
Model (ActiveRecord )

Using validations like validates_presence_of, validates_uniqueness_of, validates_size_of,validates_format_of etc.
Using association for specifying relationships in the tables using has_one,has_many, belongs_to etc.
Using named_scope to classify and access records. Include and joins are used to access data from tables and query data.

Day 3
View ( ActionView )

Using views in html and haml files.
Using haml with right indentation are important as the ending tag depends on this.
Including javascript/stylesheets in views by using the include and link tag respectively.
Using different types of ajax tags like link_to_function,form_remote_tag etc which is used to harness the power of javascript library.
Using Partials we can have the same view has to retained on multiple pages. The layout file is used to specify the background of the page which is made to be used for multiple pages or for just single pages by mentioning it on the controller as layout "filename".
Using Yield to insert contents on a particular layout.
Using Render to show the same page again with the parameters already present in the response while redirect is used to tranfer the response to a different function and then to a different view.

Day 4
Controller ( ActionController )

Using facility within the application that directs traffic, on the one hand querying the models for specific data, and on the other hand organizing that data (searching, sorting, massaging it) into a form that fits the needs of a given view.
Managing the layout in application that is to be used for the views from that controller.
Using access specifiers like public,private for methods on the controller.
Using filters on controller like before_filter and callbacks which are like after_create, before_save, after_save etc.

Day 5
Migration Scripts

Creating Rails migrations for creating tables , manipulating columns in it.
For specifying its data structure.
Creating up and down blocks for it.
Specific migration can be run and it can also be reverted using different migration command.
Migration files are created when a model is created also additional migration files can be created for inserting columns to table later on.

All Days
Working on git, gems

Using git for version management.
Creating account on git, uploading private keys on it,
Using git for cloning code from origin, making git repository,creating new branches, merging branches with master, pulling and pushing code from origin and to origin.
Using gems for additional features e.g.
seed_fu,
paperclip,
s3,
authologic,
facebooker,
twitteroauth,
fckeditor,
act_as_ferret,
will_paginate,
rmagick,
etc..
Using bundler and Maintaining differnt section in gemfile for development,production and testing.

On Weekend :)
Deploying App on Cloud (Heroku)

Using heroku for deploying application.
Creating application according to the heroku requiremeent as on heroku we have time limit for request and response.
Using amazon s3 for storing files as Heroku does not file storage on it. Creating rake tasks for that.
Using gems which supports heroku.
Using heroku commands,
e.g heroku logs, heroku rake etc.


Philosphy that Developer lives everyday
TDD(Test Driven Developement), DRY ( Do Not Repeat Yourself)

Wednesday, March 23, 2011

Rails 2 to Rails 3 Migration

Recently I got engaged with assignment to help one of my client in migrating his Rails 2 app to Rails 3. The engagement was interesting and quite demanding. I am sharing this experience which may of interest to some of you guys.
Steps taken

1) First made sure that I have rvm installed so that i can switch between ruby versions easily.

$ bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )
Then put the following line in .bashrc. This line loads rvm on system.
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
$ rvm install 1.9.2 $ rvm use 1.9.2
$ gem install rails --version=3.0.3


2) Switch to your existing system ruby verion(in my case it was ruby 1.8.7) and start migrating your existing rails 2 project. I have taken help of rails_upgrade plugin for the same

$ rvm system
$ cd myproject
$ script/plugin install git://github.com/rails/rails_upgrade.git


3) Once plugin installed then run rake tasks

# Check your app for required upgrades
rake rails:upgrade:check

# Backup your likely modified files that might be overwritten by the generator
rake rails:upgrade:backup

# Generate a new route file
rake rails:upgrade:routes

# Generate a Gemfile from your config.gem directives
rake rails:upgrade:gems

# Generate code for a new config/application.rb from your environment.rb
rake rails:upgrade:configuration

4) Now its time to go back to your backed up files and pick up your application specific code and put it in upgraded files
5) Now switch to rails 3 using rvm and start your app


$ rvm use 1.9.2
$ rails server

6) If you do not get any error then that will be surprise as you will definitely get tons of errors and its time to attack one by one

frequest type of error you will be sseing are
a) gem not installed -> please make sure that you have added entry in .Gemfile and used bundle install command
b) gem version mismatch -> find out verion that supports rails 3(ruby 1.9.2)
c) some modifications in application.rb
d) html corruption -> please use html safe functions .html_safe

7) now you need to check each page one by one and sort out any issues.

Overall its a great experience and offcourse I could do it with help of ample onlie help available on opensource communities.
I will like you not to miss following links
rails upgrate plugin
rails cast on rails 3 migration
rails cast on rails 3 routing

Sunday, June 28, 2009

Engaging web2.0 to go greener

LAMP Technology + a simple logic for radius search + thinking in web2.0 way for greener life = thevillagegreener.com
I am really happy the way people behind it made it a platform to fuel a greener lifestyle. I am proud to be part of the team and could help to realize the thoughts on technology front.
The Village Greener aims to help you find and fuel your greener lifestyle by equipping you with intelligence and opportunities for action. The Village Greener encourages those interested in making ecologically sound daily lifestyle choices to gather here — and then to share, learn and do things to live a little greener. Everyday. In small ways that add up to big change.
One may see features like rating a listing, calendar events, a website blog, having teasers for people through media like books, videos. But blending the same to give a very simple and intuitive platform for users who want to propogate their green lifestyle is unique.
The most important thing in the site was navigability and search.
Enabling users to search their product nearest to them, "local" to them. Knowing more about a service provider who is also providing service in other locations.
Technologies chosen to shape up the things
1) mod_rewrite for enabling SEF urls
2) Joomla 1.5 to act as backend CMS
3) SOBI Radius search plugin with many customisations for ZIP search
4) Rating component
5) Events and Calendar component to publish event
6) Javascript gadgets for video sharing

The beta to be released soon and will write more once its open.

Wednesday, June 3, 2009

New release of RDR

As came new rails 2.3 with more n more new stuff and making your app more DRY ( Do not Repeat Yourself) I have gone ahead and released new RDR Rails Dynamic Routes for rails 2.3.
The new release RDR2_3_2 is implemented in Rails 2.3.2 and compatible with Rails 2.2.x and above. I made some changes in new release like create actions with web-service support. for this I have used "respond_to" feature of Action Controller which determines the desired response format(html/xml) from the HTTP Accept header submitted by the client.

Hopefully you will like it..

Friday, May 29, 2009

RDR : Rails Dynamic Routes

While working on a CMS project we came across with requirement to build SEF urls dynamically in rails. rails have out-of-the-box support for SEF urls having routes.rb.
But what if I need to add new SEF urls without restarting server.. dynamically.
This need gave birth to RDR Rails Dynamic Routes. This is pretty simple utility that I have share on rubyforge. This will enable you to define customised(user friendly) url mapping for your selected controller/action making rails' routes.rb dynamic. No need to have server restart new url mapping is loaded dynamically. No additional dependency of any gems. You can also keep track of new updates on Rubyforge

Enjoy!!

Saturday, May 23, 2009

Evaluating Amazon EC2 for a new startup

Recently I got involved in shaping up a new job portal site. While architecting the application I was sure that it will be best to go for Amazon S3(Simple Storage Service) for storing my unstructured data in forms of pdf, word-docs, ppts. When I started thinking upon deployment options I started digging into Amazon EC2 . This was some interesting thing that I want share about..
We were very clear about our plan. The steps till final release we defined were 1) nightly build release 2) alpha release 3) beta release

Nightly build release is just for developers and testers. alpha release is going to be accessed by some real market users ( a trial access invitations being sent to few top recruiters in US market) and once its accepted by industry then beta release with some marketing. Plan was to have 500 odd recruiters and 5000~6000 candidates in first 3~4 months, which was very modest. But We wanted to keep the application scalable and our deployment architecture such that we can go and keep adding city after city ..Boston..Chicago..NewYork..and so on.. the way craigslist done !

After so much of buzz of "cloud computing" , adding up of Elastic term by Amazon I seriously started looking for it.. claims are really promising.. you are paying only for what you are using and you can scale it factor-n without any hassle and very rapidly.

Big question for us was whether to go for EC2 service from day one? Will it be cost effective from day one?

I started searching answer for these questions.. I revisited pricing of Amazon EC2.

The pricing below is based on data transferred "in" and "out" of Amazon EC2.

Data Transfer In
All Data Transfer $0.10 per GB

So I am going to pay $0.10 for every GB starting from my first byte. When I requested for some quotes from hosting service provider for dedicated server , I got response with quotes ranging from 5$ to 75$ per month with 1500 GB bandwidth included.
It was appearant that if my bandwidth usage is going to be above 500 GB but below 1500 GB then dedicated server is the best bargain for me.. but the day I start consuming more than 1500 GB bandwidth amazon Ec2 would turn me cheaper and also very scalable solution..

Decision was obvious start with a dedicated server and switch to EC2 when you are real candidate for it.. when you really are a growing and scaling application.

So take a pill only when you require it and if you require it :)

Monday, May 18, 2009

Nofollow script for SEO experts

After requested again and again from my SEO expert colleagues, I thought its high time to device something very basic but good tool fir my friends.
nofollow is an HTML attribute value used to instruct some search engines that a hyperlink should not influence the link target's ranking in the search engine's index. SEO experts want to build links for their pages and get their page ranked up high on yahoo/google/msn search engines.
you will get exact idea about how different search engine treats "nofollow" tag from following chart

rel="nofollow" Action Google Yahoo! MSN Search Ask.com
Follows the link Yes Yes Yes Yes
Indexes the "linked to" page No Yes No Yes
Shows the existence of the link Only for a previously indexed page Yes Yes Yes
In SERPs for anchor text Only for a previously indexed page Yes Only for a previously indexed page Yes
courtsey : wikipedia.org
The demand is that when server serves html to bot it should add rel="nofollow" to all external links. Another caveat was that it should not add nofollow to links whose class is "letmefollow"
The solution must be very easy to implement shud not require changes in existing code base php/html

I had played with apache filter in my previous projects . With new APR introduced in Apache2.0 output filtering became more easy and more clean and efficient. Also most of the hosting service provide with apache 2.0 provides mod_ext_filter module enabled in their installation. I deviced a very simple apache output filter using "sed" command. I had to use some advance sed options linke block, goto for this case.

So basically solutions was mainly doing following things
1) configure mod_ext filter
2) add environment variable using apache setenvif instruction
3) enable filter only for bots "bot" in User_Agent field of http request

If anybody wants me to know more on this then please contact me.