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

Older Posts


April 2017
« Feb    

Power Shots


The Classic...

red awakening

Night Lights

Safely Home

Ein kleines bisschen von Allem

, Gambel's Quail,

Akaroa Aurora

Jokulsarlon Beach, iceland

Wooden Lighthouse

More Photos