views:

86

answers:

1

Good afternoon,

I'm trying to render as XML the complete ActiveRecord error list, problem is when you do something like:

respond_to do |format|
   format.xml { render :xml => @object }
end

It does not render nested attributes if you don't say so, so either: you should create a template or calling explicity to_xml method and using ":include". This last option seems to work fine with nested attributes on model associations. But what if we got errors? This code does not work:

respond_to do |format|
   format.xml { render :xml => @client.to_xml(:include => :errors }
end

I know I could do @client.errors and even hide .to_xml, but now i want to do something like:

   respond_to do |format|
       format.xml { render :xml => @client.to_xml(:include => {
                                        :errors, 
                                        :client_contact => {:include => :errors } } )}
    end

And supposedly I could obtain only in 1 xml, the errors from the client, and the errors from the client.client_contact! Let me know if i'm doing something wrong, or this :include is not supposed to work with errors

Regards

+1  A: 

Have a look at the documentation for XML builder in the API docs. You can generate XML based on any number of conditions and output it however you like.

There's also a Railscasts episode showing you how to do a similar thing for RSS feeds.

bensie