Validates_xxxx_of messages extraction

Hi,

I have used validates_xxxx_of method in the model. Here is an extract
of the returned object:

0: &id001 !ruby/object:ProductOption
attributes:
time_last_modified: *id002
name: nnn
color:
errors: !ruby/object:ActiveRecord::Errors
base: *id003
errors:
name:
- invalid name
- name missing
color:
- invalid color
- color missing
new_record: true
1: &id003 …

As you can see, there is an index for the object, because I am saving
multiple records in the same time.

I know that I can access to the errors by
error_messages_for/each_full_messages method, however, I am not sure how
to use it in my case.

So, is there a way to access to the errors “invalid name”, “name
missing”, etc. in the model and construct a more meaningful object to
return to the controller?

Thanks!

On 5 October 2006 14:40, Ianne L. wrote:

I have used validates_xxxx_of method in the model.

So, is there a way to access to the errors “invalid name”, “name
missing”, etc. in the model and construct a more meaningful object to
return to the controller?
You can access myModel.errors.on(attribute) to get all errors for that
attribute.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs