« Sharding with Cookie-Based Sessions | Main | Don't Lend Friends and Family Money! Why? »

January 12, 2008

Ordering error_messages_for in Rails

Due to laziness, I have not, in the past, given much back to the open-source community. I would like to start doing so.

For the most part, I think Rails is an elegant solution to web application development. That is why I find it shocking that error_messages_for is still unordered due to hash storage. It is a pet peeve of mine to get a form with multiple errors that do not match the order presentation by the form. It just seems sloppy.

Anyways, I took the time to write a plugin named ordered_error_messages_for. It extends the core so that if you supply :order=>[:attr1,:attr2, …] to error_messages_for(…) you get a clean orderly display of errors.

Example:

error_messages_for(:user, :order=>[:name,:password,:phone_number])
error_messages_for(:user, :order=>{:user=>[:name,:password,:phone_number]})

Install it with a:

./script/plugin install http://orderederrors.rubyforge.org/svn/ordered_error_messages_for

More information at:
orderederrrors on RubyForge

Sexy. Rails Sexy.

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/t/trackback/2825034/25060082

Listed below are links to weblogs that reference Ordering error_messages_for in Rails:

Comments

Feed You can follow this conversation by subscribing to the comment feed for this post.

Wow,
Its workign fine thanks a lot

Hi,
I have already installed another plugin i.e custom_error_messages .

and i installed your plugin .. so your plugin and also custom_error_messages plugin is not working

if you have any idea plz reply

You are flippin' awesome... I've been trying to order them using nested ifs, which is hardly the Rails way, and doesn't work anyway for some unknown reason... At least this way I'll have a little more control...

I'm in total agreement that the function could use some updating... Have you thought about offering the code to Rails proper? They're just about to do a feature lock for 2.1 I think, so now would be the time if you were going to. Just a thought anyway :)

Thanks!

Post a comment

If you have a TypeKey or TypePad account, please Sign In