Simple Captcha Released

Hey guys, finally i have released the captcha plugin for public usage.

Check it out here

February 7, 2007 at 1:38 am Leave a comment

Blog moved to — releasing the captcha plugin with multiple styles of clear images, with random string text

Hi Everbody !!

I am moving this blog to Expressica

and i would like to inform all the readers to update their feeds and bookmarks to the new url .

On my new blog i am going to release a captcha plugin which is really very simple to implement. This plugin provides the functionality to add captcha based authentication in your rails applications.

It mainly features…

  • Controller based captcha
  • Model based captcha
  • and the feature i like the most is multiple image styles

You can simply pass the name of the image style from the view and captcha will throw the random strings as the selected style of image. The images are clear enough to read by human and blurred and manipulated enough to protect from bots.
Example of the images …

  • simply_red
  • simply_green
  • simply_blue
  • embosed_silver
  • distorted_black
  • all_black
  • charcoal_grey
  • almost_invisible

Comments/Queries are welcome on this idea.

I will release this plugin very soon on

February 2, 2007 at 6:35 am 3 comments

Nice Experience !!

My first Barcamp was really a nice experience. Enjoyed some interesting sessions and some of them were riling me out.
But in all i can say it was good to be there and i will try to attend the all of them in the future.

December 11, 2006 at 6:17 am Leave a comment

Going to BarcampDelhi-2

BarcampDelhi-2 is all set to create a nice geeky happening on 9th december 2006. I am luckily attending the camp and the bar.
Barcamp is all about sharing new thoughts, discussing new technologies, talking web standards.
This time it is supposed to be rich in ruby and rails as rails is really booming everywhere.
I was even planning to give a presentation on Meta Programming in Ruby but at the moment the idea is in shade as we thought that the people there might not be as comfortable with ruby to pick the meta programming things interesting. So, now i have planned to present it somewhere in the ruby/rails workshop kinda meetups.

December 8, 2006 at 11:18 am Leave a comment

Sample Rails Application – A demo for the ajax based drag drop tree in rubyonrails

I have provided the source code of the ajax based drag drop tree in rubyonrails in one of my previous posts.
I found some of the people are getting problems to incorporate the code into their running applications so i am providing a sample rails application in which all the code for tree is already been placed well.
However the code written seems to be lagged behind the current trends followed in rails development coz of the fire growth of rails itself, but its simply that when i wrote this tree i was very new to rails so you may find the code looks like an old wine but still tastes good to go with.


Four simple steps to make the tree working…

  1. DOWNLOAD the sample application. (let me know if you are getting any error in downloading the application.)
  2. Create a test database in mysql or modify the file /config/database.yml according to the database and user u need.
  3. Run the command
    ajaxtree> rake db:migrate

    from the application root.

  4. Run the application server by running
    ajaxtree> ruby script/server

    and watch the working tree at http://localhost:3000

November 26, 2006 at 9:44 am 55 comments

Javascript Validations and Encryptions — how to use javascript encryptions in rails.

A Quick Review on ENCRYPTIONS
We all are very familiar with the ruby encryptions we usually implement SHA1 or MD5 in our rails applications. In my ongoing project i have been through encryptions in little bit more depth.
MD5 was the most widely used hash algorithm, it converts a string into a 32 characters long hashed key. Then comes the SHASecure Hash Algorith. SHA is a series of hash algorithms and its first member is SHA-0 however soon its usage was replaced by the successor SHA-1 and thereafter SHA-0 was never used again. The current members to the SHA series are SHA-1, SHA-224, SHA-256, SHA-384 and the latest SHA-512. At this moment SHA-1 is considered to be the successor of MD5 because of the usage and popularity statistics.
However SHA-224, SHA-256, SHA-384 and SHA-256 are collectively known as SHA-2 series.
Till yet SHA-0 and SHA-1 have been reported attacked but no attack has been found on SHA-2 series.(took from wiki)

Here we will discuss the javascript and ruby based encryptions for SHA-256 only.

Javascript Encryption in Ruby on Rails

If you need to encrypt the password at client side in ror or any other web-based form submission so that the real password string can not reach the server you can you can download the Javascript Encryption files from here. There is all collection of the javascript encryption files available in the above archive. You will not need all of them. Put the file sha256.js in the /public/javascripts/ directory of your rails application.
Now lets take the example of Reset Password where encryption is a must.
This is how you can make your view say reset_password.rhtml

<%= javascript_include_tag 'sha256' %>
<script type="text/javascript">
// <![CDATA[
  function hashPassword() {
  reg = new RegExp(/^(?=.*\d)(?=.*([a-z]|[A-Z]))([\x20-\x7E]){8,40}$/);
  document.reset_password.realpass.value = hex_sha256($F('password'));
  $('password_confirmation').value = '';
  $('password').value = '';
  return true
  $('errors_in_pass').innerHTML = "Password should match confirmation.<br />Password should contain at least one letter and one integer.<br />Password length should be 8 to 40 characters long.<br />";
  $('password_confirmation').value = '';
  $('password').value = '';
  return false
// ]]>
<h1>Change Password</h1>
<div style="display:none;" id="updating">Updating Password</div>
<div id = "reset_password">
<div style = "color:red" id = "errors_in_pass"><%= flash[:notice] %></div>
<% form_for :person, @person, :url => {:action => "reset_password"}, :html => {:name => "reset_password",:onsubmit => "return hashPassword()"} do |f| %>
<%= hidden_field_tag 'realpass' %>
        New Password
        <%= f.password_field :password, :id=>"password", :class => "field text", :value=>"" %>
	Confirm New Password
        <%= f.password_field :password_confirmation, :id=>"password_confirmation", :class => "field text", :value=>"" %>
	<%= f.submit_tag "Continue" %>
<% end %>

However it may possible that a user have disabled the javascript of the browser. In that case we will need to add the encryption at server side too. In rubyonrails we can easily handle the SHA256 encryption for let say password by adding the code

require "digest/sha2"

hashed_password = Digest::SHA256.hexdigest("password_string")

in an appropriate position in the controller.

November 14, 2006 at 8:14 pm 2 comments

Integration Testing in Ruby on Rails — How to maintain sessions while testing in Rails

Well, its a natural feel to get amazed out of every other delighted feature provided by RubyonRails and so appreciating it before actually talking about the feature in every second post. This line is for those people who have published that the worst thing about rails is that every rails programmer always just focus on the appreciation of rails and not on the framework per se. As i think the reason behind his(let say) perception is that he might not have tried rails and probably in all posts he have been through yet is that he would have got jealous out of gaining popularity of ruby on rails over jsp and asp and else, and therefore he might not be reading the whole post due to which he just remained untouched with the real appreciable features.
Anyhow, here is my post on a fantastic rails feature – Integration Testing…
RoR is the only web application framework which provides an inbuilt high level of testing. Out of the whole testing the most interesting real time testing is Integrations Testing where you can synchronize with the sessions too unlike in the Functional Testing.

Where exactly we should use Integration Testing ?
Whenever we need to test a series of functionalities which belongs to more than one controller , we should go for Integration Testing and not the Functional one.

Since the functional and unit testing are controller and model centric respectively, rails automatically creates the related functional and unit tests files. But as integrations testing is not confined in any criteria of a specific controller or model, we have to create the integrations file manually… Well, nothing is headache in rails. Its a simple pre-written script, all you need is to call that script with a name you like for whole story you wish to test in the integration test.

Here is a real example of Integration Test in Ruby on Rails

Considerations for test…
We will simply test

  • signing in
  • posting a new article
  • deleting an article with xml_http_request (ajax post request)

Create the test file by running

ruby script/generate integration_test initial_features

Make sure that now you have the file /test/integration/initial_features_test.rb. Rails automatically appends _test at the end of the file name.

For god sake Lets start the testing now 🙂
Code for the file /test/integration/initial_features_test.rb

require "#{File.dirname(__FILE__)}/../test_helper"

class InitialFeaturesTest < ActionController::IntegrationTest
  fixtures :users, :articles

  def test_initial_features
     user = user_for_test

  def user_for_test
    open_session do |user|
      def user.try_to_signin
        assert_nil session[:user] # assert_session_has & _has_no have been deprecated
        get "user/signin"
        assert_response :success
        post "user/signin", :email=>"test failure string", :password=>"test failure string"
        assert_nil session[:user]
      def user.signin
        assert_nil session[:user]
        user = users(:first)
        post "user/signin", :email=>, :password=>user.password
        assert_not_nil session[:user]
        assert_response :redirect
        assert_redirected_to "articles/show"
        # now as the session is set once, we need not to signin again
      def user.post_an_article
        get "articles/show"
        assert_response :success
        assert_template "articles/show"
        user = session[:user]
        articles_count = user.articles.length
        post_via_redirect "article/new", :title=>"Integration Tetsing in Rails", :description=>"another relishing rails feature"
        assert_template "articles/show"
        assert_equal, user.reload.articles.length
      def user.delete_an_article_with_xhr
        user = session[:user]
        articles_count = user.articles.length
        xml_http_request "articles/delete", :id=>articles(:first).id
        assert_equal articles_count-1,user.reload.articles.length


Although these are not that high level integration tests that rails can provide but its just an overview on the integration tests. I will explain them soon.

November 2, 2006 at 5:52 pm 2 comments

RoR(Ruby on Rails) in India – Ruby on Rails based Indian Company

Ruby on Rails is creating the storms in the web development all over the world. RoR is even capable to challenge Big Caps like Microsoft’s Asp.NET and so everything else in the specific area. World is continuously changing… The current WEB not solely depends on the old,encoded,paid,stressful technologies but the fresh,open-source,free,joyful technologies like Ruby on Rails are now creating the new highways to connect the WEB… What else ?.. Providing a beautiful atmosphere to web-developers. At the moment the whole world of web-development is cherishing the fresh breeze of RoR.
How much of INDIA is delighted by Ruby on Rails ?
Currently, the INDIAN side of Rails is a small community…but growing at a rapid rate. I am proudly working at VINSOL(New Delhi,India), a company full fledged working on rails.
VINSOL is currently holding some good clients for web-development and providing efficient services in Ruby on Rails.

October 25, 2006 at 7:48 am 3 comments

Captcha in Ruby on Rails – Customize the use of captcha in the plugin validates_captcha

Hello Everyone !!
I have released a captcha plugin Simple Captcha. It is really simple to implement, and provides a cool feature of multiple styles of images.

Previous Post for validates_captcha

To implement captcha in RubyonRails, validates_captcha plugin can be a good option but a small customization i need with this plugin was to use it on some specific action and not to be validated the captcha field every time an instance of the model is saved or updated.
Here is a small work-around for its customization…
How to use customized captcha in RoR ?
Install the plugin validates_captcha in your rails application by running this command from the root of your application

ruby script/plugin install

Make sure that you can now see the directory vedor/plugins/validates_captcha.

Now run these commands from your application root to make the image and data directories

  ruby script/generate captcha store_directory
  ruby script/generate captcha image_directory

Here is the complete API for the usage of this plugin. I am describing the same idea as given in this API but in a bit more specific means.

Lets consider a model User in which we will implement the captcha.
Add the following code in the file app/models/user.rb

  class User < ActiveRecord::Base

    validates_captcha :if => :request_captcha_validation?
    attr_accessor :request_captcha_validation

    def request_captcha_validation?
      (self.request_captcha_validation==true)? true : false


Handle View and Controller

Add the code in the view inside your existing form.

  <% c = prepare_captcha :type => :image -%>
  <%= captcha_hidden_field c, 'user' %>
  <%= captcha_image_tag c %>
  <%= captcha_label 'user', 'Type in the text from the image above' %>
  <%= captcha_text_field 'user' %>

Your controller will look like

  def save
    # the line in bold represents that you need captcha validation.
    # if captcha validation is not required then remove this line from your controller.
    @user =[:user])
    @user.request_captcha_validation = true

However image is too noisy and it contains repeated strings.
To improve the quality of images generated by the plugin validates_captcha visit Here.

October 24, 2006 at 6:59 pm 50 comments

MicroSoft’s IE-7 Released – another headache for web developers.

Current World’s software giant Microsoft finally released the new milestone IE-7.
Once again web programmers have to reload their guns to cross a new barrirer of all new standards of MicroSoft another thing IE-7.
Its a feel of proud for Microsoft to not to follow the web-standards of W3C and to give themselves a fresh new region of narrow mentality people and a feel of headache for web developers to again customizing their previous running web-sites which already been specially customized to go ok with a mess IE-6 and here is a repeated story again coz the most amazing thing is that IE-7 is even not following the styles of IE-6

Go FireFox !! Go Flock !!

October 21, 2006 at 7:07 pm 2 comments

Older Posts


December 2021

Power Shots