Hello group- The validates_xxx helpers provide a '':message'' parameter to customize the message somewhat. However, they always prefix this message with the table column name that caused the trouble. Is there a way to turn this part off so that the custom message is the only thing displayed? i.e., rather than say: Name_funky is already being used. I''d like a validated_uniqueness_of to say something like: Your funky name is already being used. Please choose another. Jake -- Posted via http://www.ruby-forum.com/.
I just wrote up a hot to page on the Rails wiki http://wiki.rubyonrails.org/rails/pages/HowToWritePluginToModifyRailsCore This might be one way to go for you. -Peter On 11/25/05, Jake Janovetz <jakejanovetz-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> > Hello group- > > The validates_xxx helpers provide a '':message'' parameter to customize > the message somewhat. However, they always prefix this message with the > table column name that caused the trouble. Is there a way to turn this > part off so that the custom message is the only thing displayed? > > i.e., rather than say: > > Name_funky is already being used. > > I''d like a validated_uniqueness_of to say something like: > > Your funky name is already being used. Please choose another. > > Jake > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > 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
My example is not exactly what you want to do but using a plugin to modify the core to stop including the column name could be done I think. On 11/25/05, Peter Michaux <petermichaux-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I just wrote up a hot to page on the Rails wiki > > http://wiki.rubyonrails.org/rails/pages/HowToWritePluginToModifyRailsCore > > This might be one way to go for you. > > -Peter > > On 11/25/05, Jake Janovetz <jakejanovetz-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote: > > > > Hello group- > > > > The validates_xxx helpers provide a '':message'' parameter to customize > > the message somewhat. However, they always prefix this message with the > > table column name that caused the trouble. Is there a way to turn this > > part off so that the custom message is the only thing displayed? > > > > i.e., rather than say: > > > > Name_funky is already being used. > > > > I''d like a validated_uniqueness_of to say something like: > > > > Your funky name is already being used. Please choose another. > > > > Jake > > > > -- > > Posted via http://www.ruby-forum.com/. > > _______________________________________________ > > 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
Thanks. I''ve seen how to change the default error messages and I think that''s useful in many cases. However, I''m curious how ''real'' apps do validation. The validates_xxx framework seems pretty limited -- not quite as limited as the scaffolding, but in a similar vein. I imagine commercial apps want a more custom way of handling validation results, but I don''t quite see the best way to do it. What I mean to say is that the helpers are nice and suit many needs, but do people generally throw them out and replace them with custom validation stuff? In the end, the helpers are useful and I don''t want to rewrite all that logic, but I don''t quite see the most economical way of attaching my own view to these helpers. Jake petermichaux wrote:> My example is not exactly what you want to do but using a plugin to > modify > the core to stop including the column name could be done I think.-- Posted via http://www.ruby-forum.com/.
At the risk of being flamed, "Me too! Me too!" I had expected (Dave Thomas said Ruby and Rails is terribly intuitive!) that if I override the error message with :message, that it would replace the whole thing, as Jake also lamented here. Like him (and his "Name funky" attribute) I have an attribute that doesn''t work very well in a message, and of course it blows the whole i18n possibility right out the water! Hendie Dijkman Calgary, AB
It is not that hard, i use the following method : validates_presence_of :email , :message=>''Your message'' then you create a method in you helper that you pass a object or add a method to the rails code def my_error_message(object) html = "<h1>ERROR<h1>" html += "<ul>" object.errors.each do | field , message | html += "<li>#{message}</li>" end html += "</ul>" html end Use in your views as <%= my_error_message(@customer) %> -- Posted via http://www.ruby-forum.com/.
On 11/25/05, Hendie Dijkman wrote:> > Dave Thomas said Ruby and Rails is terribly intuitive!Terribly intuitive rather than fantastically intuitive? :S gulp _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Hendie, I just posted a message announcing a plugin which allows you to customize validation messages. A side effect of this plugin is that it allows for easier localization of messages since you''re free to put the fieldname placeholder anywhere you like. Let me know if it works for you. Hammed On 26/11/05, Hendie Dijkman <ruby-Vki3jUAxBCcyzzc7d281tmfPcZCv/ETZ@public.gmane.org> wrote:> At the risk of being flamed, "Me too! Me too!" > > I had expected (Dave Thomas said Ruby and Rails is terribly > intuitive!) that if I override the error message with :message, that > it would replace the whole thing, as Jake also lamented here. Like him > (and his "Name funky" attribute) I have an attribute that doesn''t work > very well in a message, and of course it blows the whole i18n > possibility right out the water! > > Hendie Dijkman > Calgary, AB > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >