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_validation_messages/ 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
> results in: Need at least 10 feet of Rope to hang yourselfHow morbid.. Nice plugin! Rob
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 26/11/05, Robert <mannl-KK0ffGbhmjU@public.gmane.org> wrote:> > results in: Need at least 10 feet of Rope to hang yourself > How morbid.. > > Nice plugin! > > > > Rob > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
On 11/26/05, Robert <mannl-KK0ffGbhmjU@public.gmane.org> 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-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Best Regards, -Larry "Work, work, work...there is no satisfactory alternative." --- E.Taft Benson _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
to install the plugin: script/plugin install http://estound.com/svn/rails/plugins/custom_validation_messages/
Well done Hammed! Just what I needed! It works as advertised. :) H.
Excellent, I''m sure this will be a boon for localization efforts too. On 11/26/05, Hendie Dijkman <hendie-Vki3jUAxBCcyzzc7d281tmfPcZCv/ETZ@public.gmane.org> wrote:> Well done Hammed! > > Just what I needed! It works as advertised. :) > > H. > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Thanks to all for the positive feedback. If no issues are found with this, I''ll submit it as a patch. Hammed On 26/11/05, Kyle Maxwell <kyle-FOSOgQihYpQjo0HpFSRKWA@public.gmane.org> wrote:> Excellent, I''m sure this will be a boon for localization efforts too. > > On 11/26/05, Hendie Dijkman <hendie-Vki3jUAxBCcyzzc7d281tmfPcZCv/ETZ@public.gmane.org> wrote: > > Well done Hammed! > > > > Just what I needed! It works as advertised. :) > > > > H. > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
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 (drawn.boy-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org)
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 27/11/05, drawnboy <drawn.boy-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 > (drawn.boy-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org) > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
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 drawn.boy-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org