This project is archived and is in readonly mode.
Add 'field' attribute to ActiveRecord::Errors#to_xml
-
labria
Yes, that would be quite useful, +1 on that!
-
Max Lapshin
- Tag changed from 2-3-stable, 3.0, activerecord, active_record, to_xml, xml to 2-3-stable, 3.0, activerecord, active_record, feature, test, to_xml, xml
I've found this patch rather useful and we've tested it in our RIA, that can now highlight fields.
-
bluefuton
+1 - currently doing this manually and it'd be be great if it was the default behaviour.
-
David Trasbo
+1
This would definitely be a useful change. Unfortunately the patch no longer applies because the
Errorsclass has been moved toActiveModel.I've made a new patch which applies to the master branch at the time of writing. I've named the attribute that specifies which field the error message applies to "on", but feedback on that choice is welcome.
-
David Trasbo
Oops. Looks like I forgot to attach the patch. Here you go:
-
Martin Andert
See also Ticket #1625 Allow active record errors to_xml to return separate tags for attribute and m....
Instead of
<error field="...">...</error>I would prefer
<error on="...">...</error>like in
error_messages_on. -
subimage
+1 on this. It's puzzling that errors.to_json properly shows the field names, but not to_xml.
Was going to look into implementing this for my API, but I'll apply the patch instead. Thanks!
-
Neeraj Singh
+1 the patch works.
I agree with Martin that the attribute name should be 'field' instead of 'on'.
-
zhshxa
- Importance changed from to
David Trasbo,
The last patch does not work.
I must made below change:
options[:builder].errors do |e| self.each do |attr, messages| Array.wrap(messages).each do |msg| e.error(msg, :on => attr) end end end-Sandy
-
Ryan Bigg
Automatic cleanup of spam.
-
rails
- State changed from new to open
This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.
Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.
-
rails
- State changed from open to stale
-
bluefuton
- Tag set to activerecord
This issue still exists in Rails 3.0.7. It's easy to retrieve the attribute name from the to_json output, but it is not included when using to_xml.
>> zebra.errors => #<OrderedHash {:name=>["can't be blank"]}> >> zebra.errors.to_xml => "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>\n <error>Name can't be blank</error>\n</errors>\n" >> zebra.errors.to_json => "{\"name\":[\"can't be blank\"]}"[state:open]
