I'm generating 3 models on 1 controller and i'm rescuing
ActiveRecord::RecordInvalid for validation errors, however 2 of the
models have the same attribute called "name", and if there's an error on
that field, I wouldn't know whether that belongs to model A or model B.
What then is the best way of modifying the error message of a validation
error without having to rely on locales which I think ActiveRecord
encourages you to do.
Currently, my solution is overriding the RecordInvalid#initialize
(adding "model class: #{record.class}" to the :errors hash value), but I
dont think this is a clean solution.
module ActiveRecord
class RecordInvalid
def initialize(record)
@record = record
errors = @record.errors.full_messages.join(
I18n.t('support.array.words_connector', :default => ', ')
)
super(I18n.t('activerecord.errors.messages.record_invalid',
:errors => "model class: #{record.class}: #{errors}"))
end
end
end
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.