Currency converter in Rails

February 17, 2008

Recently I was searching for a library in Rails, which can be used as currency converter app. After searching the blogs and rubyforge I decided to write it on my own :). For me its working perfectly however I am open for your feedback on the same. Feel free to use it for your rails development and share your experience.

This can be downloaded from rubyforge at

If this link doesn’t work for you , feel free to send me a message


Ajax Pagination

August 26, 2007

This pagination facilates retrieving of photos from database with AJAX.

1.Create partial in views.Add following code to it.

0), :update => “your div id“,
:url => {:action => :imgstrip, :id => post, :skip => ([0,skip.to_i-1].max) } if post.medias.size>4 –>

break if (cnt+=1)==5

0), :update => “your div id“,
:url => {:action => ‘action‘, :id => post, :skip => ([0,[skip.to_i+1,post.medias.size-4].min].max) }if post.medias.size>4 –>

Replace “post” with “your object

2.To render template add following line to views

render :partial => ‘template‘, :locals => { :post => post, :skip => params[:skip] }

3.Add following in controller.rb

def action
post = Post.find params[:id]
render :partial => ‘template’ :locals => { :post => post, :skip => params[:skip] }

Replace ‘template’ with your view name.
This will show four photos after each scroll.


Naveen Joshi


August 26, 2007

Lightbox is a simple script used to overlay images on the current page.
It gives the fancy visual effects and provides the functionality to create album of related images and allows navigation through them with ease.

Setup for lightbox -:

1. It uses “Prototype” javascript library and “Scriptaculous” javascript library(for visual effects).So you have to include this 2 libraries in your tempalte header.

(javascript library of lightbox)
(This will give all the effects in scriptaculous.)
(This will include all the javascripts required for all ajax effects in RoR)

2.It requires CSS of lightbox.

(CSS for lightbox)

3.Check CSS and javascript for “path of the defult images” i.e prev.gif, next.gif,loading.gif,close.gif.

Activate lightbox -:

1.To give the lightbox effect add “rel=lightbox” in the image tag.
href=”/images/image-1.jpg” mce_href=”/images/image-1.jpg” rel=”lightbox” title=”my caption”>image #1

2.To have the group of related imges add rel=”lightbox[roadtrip]” in the image tag.

href=”/images/image-3.jpg” mce_href=”/images/image-3.jpg” rel=”lightbox[roadtrip]”>image #3

Download Lightboxv2.03.3 -:

The most important point-:

On every page load Lightbox automatically initialised by ‘initIightbox()’ function written in ‘lightbox.js”.Lightbox need to initialise every time to see its effects.

Thus render partial of the page does not give the lighbox effect because it does not call ‘initIightbox()’ function written in ‘lightbox.js”.so this can be solved by calling onclick =”initIightbox();” for an image.

for example-:
href=”/images/image-3.jpg” mce_href=”/images/image-3.jpg” rel=”lightbox[roadtrip]” onclick=”initLightbox();”>image #3


Naveen Joshi

Maintaining an object between two pages

June 13, 2007

I wanted to write a form where users can create or edit a claim. One of the fields is a company. Since there is an internal code for each registered company, I wanted the users to search by company name.On the form, I plan to add a link called “Search Company”. This link will take the user to another form to find a company by name, and the matching ones will be displayed as links. If the user click on any of the links, the claim form page will be redisplayed with the selected company and the rest of the data the user has entered. Right now, I had a table called claims and a model that matches it.In Java Servlet Faces, I use

<t:saveState value=”#{form}” id=”formSaved”></t:saveState> to pass the objects to the next page, but I was not sure how to do it on Rails. After digging around forums I found the following


There’s always several ways to get the skin off the cat, but just save the id of the selected company in the “session”. Something like this in the action that fires when they click on a company…

session[:selected_company_id] =
(this assumes you are returning the selection as “selected_company”)

Enjoy 🙂

My hands on Capistrano….

June 13, 2007

I was searching for a utility for deploying web applications. I found Capistrano , which is a utility for deploying web applications. I decided to try my hands with it, and my experience says It is ideal for system administration.

Advantages of Capistrano configuration -:

1.It can execute commands in parallel on multiple servers.

2.It allows to define tasks which can include commands that executed on the servers.It allows to define task specific roles for server.

3.It includes some basic templating allowing to dynamically create and deploy things like maintenance screens, configuration files, shell scripts, and more.

4. It uses repository which allows easy upgration of sorce code.

For Rails users its cool cool shot….

It can perform migrations during deployment.It can restart mongrels/fcgi.

It allows to use transactional commands.When any of the command fails changes are rolled back automatically.

To configure it following specifications are required-:

It requires SSH to connect to the servers.

The remote server is capable of understanding POSIX shell commands.

It requires subversion to manage your source code.

It require FastCGI to power your application.

After spending so many hrs I like following features -:

1.It facilitates to keep production database password secure by allowing to create host specific database yml.

2.The”sudo” helpers got a lot more powerful; allows to pass a specific set of hosts to them or even call them outside of any task by implementing capistrano scripts, basically making an entire file a single task.

3.It allows to create own deployment strategies from multiple server configuration by allowing selection of servers with their environment variables.


Naveen Joshi