<stefan.saasen-6VhMtaG8d0w@public.gmane.org>
2005-Oct-18 14:21 UTC
AW: overwriting standard form errors
Hi , just overwrite the error_messages_for method. Have a look at http://wiki.rubyonrails.org/rails/pages/OverridingRailsMessagesInAnotherLanguage Hope it helps. best regards stefan> -----Ursprüngliche Nachricht----- > Von: rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > [mailto:rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] Im Auftrag von > Jeroen Houben > Gesendet: Dienstag, 18. Oktober 2005 16:10 > An: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > Betreff: Re: [Rails] overwriting standard form errors > > Jeroen Houben wrote: > > Hi, > > > > I know how I can change individual error messages (per > model property > > so to say), but a header message is always prepended. It looks like: > > "# errors prevented you from saving the Model" > > > > I can''t spot where I would change this particular piece of text.. > > Hmm. Looking at the source, it seems like it''s hardcoded. > > # File > vendor/rails/actionpack/lib/action_view/helpers/active_record_ > helper.rb, > line 99 > 99: def error_messages_for(object_name, options = {}) > 100: options = options.symbolize_keys > 101: object = instance_variable_get("@#{object_name}") > 102: unless object.errors.empty? > 103: content_tag("div", > 104: content_tag( > 105: options[:header_tag] || "h2", > 106: "#{pluralize(object.errors.count, "error")} > prohibited this #{object_name.to_s.gsub("_", " ")} from being saved" > 107: ) + > 108: content_tag("p", "There were problems with the > following fields:") + > 109: content_tag("ul", > object.errors.full_messages.collect { > |msg| content_tag("li", msg) }), > 110: "id" => options[:id] || "errorExplanation", > "class" => > options[:class] || "errorExplanation" > 111: ) > 112: end > 113: end > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
stefan.saasen-6VhMtaG8d0w@public.gmane.org wrote:> Hi , > > just overwrite the error_messages_for method. Have a look at http://wiki.rubyonrails.org/rails/pages/OverridingRailsMessagesInAnotherLanguageYes, ovewriting is always possible, but I''d rather not do that though... There is a useful config ActiveRecord::Errors.default_error_messages that you an use for default errors. Just not the "5 errors prevented your from saving..." string. I might just not display that at all. Jeroen