Author Archives for Akhil Bansal

What do you see a face or an Eskimo?

Lib file state_select.rb

If you are not interested in installing a plugin just for one method(state_select) then You can put state_select.rb file in you rails lib directory. And include state_select.rb file in your controller where ever you want to use state_select method.
The url for state_select.rb is
Feedback please….

Plugin: state_select, generate drop down selection box for states

I have wrote my first plugin(state_select). This plugin allows to create drop down list for states, same as country_select method in rails. I know this is not a big deal…
UPDATE: Curently it can generate state list for India, US, Canada, Australia, Spain and Uganda(default is US).
state_select(object, method, country=’US’, options = {}, html_options […]

12 Balls Problem

You have 12 balls (of any kind), one ball either lighter or heavier than the other 11. A scale is provided to you but only three weighs are allowed. How can you possibly figure out which is the odd ball?

Deprecated Finders in Rails 1.1.5

These Finders are deprecated

find_first [use find(:first)]
find_all [use find(:all)]
find_on_conditions [use find(:conditions)]

Ajax pagination links: Create pagination links with link_to_remote

Here is a method by mixonix to create pagination links by link_to_remote. Copy this code in your helpers/application_helper.rb
def ajax_pagination_links(paginator, options={})
options.merge!(ActionView::Helpers::PaginationHelper::DEFAULT_OPTIONS) {|key, old, new| old}
window_pages = paginator.current.window(options[:window_size]).pages
return if window_pages.length { options[:name] => first }.update(options[:params] ))
html 1
html page }.update(options[:params] ))
html { options[:name] => last }.update( options[:params]))
and use following code for creating […]

Tab Problem in rails .rhtml files

The situation was: running Ruby 1.8.4, Rails 1.1.2, on WinXP & WEBrick server.
My application was working fine, but as I installed Rmagick my application crashed.
I got strange errors like:
compile error /script/../config/../app/views/layouts/application.rhtml:18: parse error, unexpected $, expecting kEND
if I refresh again the error actually changes(further refreshes flip back & forth between errors):
compile error
/script/../config/../app/views/layouts/application.rhtml:18: Invalid char `01′ […]

converting all newline characters to br tag

I was surprised as there is no function in ruby to convert all newline characters to <br>.
Here is a php nl2br equivalent method to convert all newline characters (\n) to break tag (<br>) in a string.
def nl2br(s)
s.gsub(/\n/, ‘<br>’)

Plugin: validate_request

A very useful plugin by Scott A. Woods.
validate_request plugin allows us to check the request method and parameters that are used to call your action.
For Example consider an add_to_cart action as:

def add_to_cart
@product = Product.find(params[:id])

The link to add an item to our cart should like store/add_to_cart/nnn, where nnn is an integer. There will be an […]

Plugin: tabnav

Add tabbed navigation to your Rails application in a easiest way.
For more details please visit

An Escalator Puzzle

Bob takes the underground train to work and uses an escalator at the railway station. If Bob runs up 6 steps of the escalator, then it takes him 52.5 seconds to reach the top of the escalator. If he runs up 14 steps of the escalator, then it takes him only 32.5 seconds to reach […]

JotSpot Live allows you, your colleagues or clients to take notes together on the same web page at the same time. Imagine everyone simultaneously typing and editing the same Microsoft Word document and you’ll get the idea. Visit

19 Rails Tricks Most Rails Coders Don’t Know

I was searching for some Rails tips and found a very good post, Click here to visit

Configuring Multiple Rails Application with Lighttpd

I was using lighttpd web server for my Rails applications.
In development mode I was starting lighttpd server from the rails application directory by
lighttpd -D -f config/lighttpd.conf
But I was facing problem when I tried to run multiple rails applications in production mode. After some trials I succeded.
I inserted the following lines of code in my /etc/lighttpd/lighttpd.conf […]

Cartographer: A Google maps API in Rails

If you want to insert google maps in your rails application, then you can use cartographer.
This is still in development.

Akhil Bansal

Myself Akhil Bansal from New Delhi, India. I have about two years of web programming experience. I work with Vinayak Solutions Pvt. Ltd, a Ruby on Rails leading company in New Delhi, India. I started my career with PHP but now I am enjoying Ruby and Ruby On Rails since last year. This blog is all about my experiences with Ruby on Rails and others. Hire Me: I’m available for contract work. Contact me at [bansalakhil30.10 at gmail dot com] if you’re interested.