Yaay! My first plugin. Validation messages prefixed with the field name have always bothered me and it seems like I'm not alone. This seemed like a fairly easy fix to attempt for my first plugin so here it is: Using this plugin you can specify exactly where in the message you'd like to see the field name or whether it should be displayed at all. Simply add a %s to the validation message and you're set. Guard the message with [ ] brackets and the field name will be banished from your message for ever. You may download the plugin from http://estound.com/svn/rails/plugins/custom_valida... Enjoy your customized messages. >From the readme: =============== This Plugin enables customization of validation error messages. Default validation error messages are always prefixed with the offending field name. This plugin allows the developer to specify exactly where the field name should be displayed in the message or whether it should be displayed at all. Tested with Rails 0.14.3 USAGE: * Include %s in message to specify where the field name should be displayed: validates_presence_of :rope, :on => :create, :message => "Can't skip %s" results in: Can't skip Rope * Messages may combine %d and %s: validates_length_of :rope, :minimum=>10, :message => "Need at least %d feet of %s to hang yourself" results in: Need at least 10 feet of Rope to hang yourself * Wrap message in [ ] to avoid field name substition validates_presence_of :joy, :on => :create, :message => "[Cheer up!]" results in: Cheer up! * %s may be specified more than once: validates_presence_of :joy, :on => :create, :message => "Happy, happy, %s, %s!" results in: Happy, happy, Joy, Joy! * Default behaviour is preserved: validates_presence_of :joy, :on => :create, :message => "is required" results in: Joy is required
on 2005-11-26 09:11
on 2005-11-26 11:32
> results in: Need at least 10 feet of Rope to hang yourself How morbid.. Nice plugin! Rob
on 2005-11-26 15:33
Thanks. > > results in: Need at least 10 feet of Rope to hang yourself > How morbid.. I tried to make the examples following make up for it :)
on 2005-11-26 16:42
On 11/26/05, Robert <email@example.com> wrote: > > > results in: Need at least 10 feet of Rope to hang yourself > How morbid.. Yup! But, it's sure hard to miss the point :) Nice plugin! Very nice! Rob > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > -- Best Regards, -Larry "Work, work, work...there is no satisfactory alternative." --- E.Taft Benson
on 2005-11-26 19:35
to install the plugin: script/plugin install http://estound.com/svn/rails/plugins/custom_valida...
on 2005-11-26 21:36
Well done Hammed! Just what I needed! It works as advertised. :) H.
on 2005-11-26 21:48
Excellent, I'm sure this will be a boon for localization efforts too.
on 2005-11-27 01:22
Thanks to all for the positive feedback. If no issues are found with this, I'll submit it as a patch. Hammed
on 2005-11-28 01:29
Hi. Hammed, it's a nice plugin! > Thanks to all for the positive feedback. > If no issues are found with this, I'll submit it as a patch. Just now my group is creating a similar plugin, and it has some function not included in your plugin. If you find the function useful, could you merge it to your code before submitting the patch? (I think marge these, it's more accetable than submit individually...) The new function customizes field names in the error view of validate. Originaly this function is for localization to Japanese environments, but I think it is also useful for in non-Japanese environments. Example usage: At a model file set_field_names :title => 'Entry Name', :description => 'Entry Description' This changes the names of the error fields "title" and "description" to "Entry Name" and "Entry Description", respectively. And it also can change 2byte-charecter (not support DB server's field name). The plugin files are stored under http://nowherenear.net:3333/tmp/set_field_names/ I hope you like it! Sorry for my broken English... -- hideaki (firstname.lastname@example.org)
on 2005-11-28 05:26
Hello Hideaki, I think you should add your plugin to the list here: http://wiki.rubyonrails.com/rails/pages/Plugins You may also want to announce it on the list to expose it to a larger audience than this thread. The ability to specify more meaningful display names is definitely useful. I've dropped it into my plugins folder. Regarding merging the two features, I think they both have a better chance of being accepted if they're submitted separately since they address related but slightly different requirements. cheers! Hammed
on 2005-11-28 10:13
Hello Hammed, > I think you should add your plugin to the list here: > > http://wiki.rubyonrails.com/rails/pages/Plugins > > You may also want to announce it on the list to expose it to a larger > audience than this thread. There is also some truth in your perspective. So, I'll try to add plugin page, and hear everyone's voice. Thank You! -- hideaki email@example.com
on 2005-12-07 23:17
Whow great thanks! these 2 plugins were exactly what i was looking for ! thanks a bunch