This was more of a Rails question than a Hobo question.
I found the answer if anyone else is interested.  The correct way is
to use the to_xml :include parameter.

It is explained here: 
http://afreshcup.com/2008/11/05/customizing-to_xml-and-to_json-in-rails/

For my example it would look something like this:
render :xml => @code.to_xml(:include => :clients)

-oillio

On May 3, 6:36 pm, oillio <[email protected]> wrote:
> I have a controller that I want to use to render xml.  The problem is
> that I want the rendered XML to also contain the data from a model
> attached through a has_many reference.
>
> I figured out a way to do it by stuffing it all in a hash.  But I hope
> there is a more elegant way as it is rather ugly.
> He is what I have:
>
> A model named Code which has the following line:
> ...
> has_many :clients, :accessible => true
> ...
>
> The controller for the Code model (named CodesController) has the
> following:
> ...
> def show
>    hobo_show do |format|
>       format.xml do
>         �...@code = Code.find params[:id]
>          render :xml => {:code => @code, :clients => @code.clients.find
> (:all)}
>       end
>       format.html { }
>    end
> end
> ...
>
> There is a better way to do this right?
>
> Thanks,
> -oillio
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Hobo 
Users" 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/hobousers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to