Tips: Replace Missing Images using JQuery

Posted by anup.narkhede on March 26, 2009

Checking for non-existing images and replacing them by placeholders is simple when the images are handled on server (db/filestore). However, for externally linked images, we can do something like this using JQuery:

This script will replace the broken image urls with ‘/images/noimage.jpg’.

JS based easy Field Validations in Rails

Posted by anup.narkhede on January 06, 2008

Most of you will disagree with this post to use Javascript based form validations in Rails. However this is an attempt to simplify integration of DEXAGOGO - Really easy field validations in Rails. This is one of the most structured and easy validation technique written by Andrew Tetlaw and team. (Demo)

To use it in Rails, copy simple_validation.rb in application lib directory and add following lines to config/environment.rb file.

Download and Import validation.js along with prototype.js in layout from here.

Two methods are introduced to render forms.

  • validated_form_for
  • validated_remote_form_for

Usage:

:class attribute refers to validation rule (or combination of rules) and :title attribute is the validation message. Details of all rules are available at http://tetlaw.id.au/view/javascript/really-easy-field-validation