Re: errors.add, setting the whole message

Max Williams
Wed, 13 Oct 2010 11:02:01 -0000

Sjoerd Andringa wrote in post #949781:
> Here you can see how the ''full_messages.format'' scope is
applied:
>
http://github.com/rails/rails/blob/v2.3.4/activerecord/lib/active_record/validations.rb#L118
> Maybe it''ll give you some insight in why it''s not
working. Perhaps
> I18n.t''s :default option is overridden? Good luck!

I figured it out, it''s not to do with I18n at all as it happens.  It
was
because i''d overriden the ActionView::Base.field_error_proc method to
wrap my errored fields in some different markup to the default, and this
was pulling in the attribute name and the error message.  So, the error
message was right all along, it was my markup generator that was wrong.
In case anyone''s interested, this is what i have now:

#override the logic/html for wrapping fields in fieldWithErrors divs in
form_for
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
  if html_tag =~ /^\<label\s/
    html_tag
  else
    error_message = instance.error_message.collect{|m|
"#{m}"}.join(",
")
" <div
class=''errorMessage''>#{error_message} #{html_tag} "
  end
end

Thanks for all your help Sjoerd
max