Hello everyone,

Partials in XML builder are proving to be non-trivial.

After some initial Google searching, I found the following to work,
although it's not 100%

     xml.foo do
         xml.id(foo.id)
         xml.created_at(foo.created_at)
         xml.last_updated(foo.updated_at)
         foo.bars.each do |bar|
             xml << render(:partial => 'bar/_bar', :locals => { :bar
=> bar })
         end
     end

this will do the trick, except the XML output is not properly
indented. the output looks something similar to:

    <foo>
      <id>1</id>
      <created_at>sometime</created_at>
      <last_updated>sometime</last_updated>
    <bar>
      ...
    </bar>
    <bar>
      ...
    </bar>
    </foo>

The ``<bar>`` element should align underneath the ``<last_updated>``
element, it is a child of ``<foo>`` like this:

    <foo>
      <id>1</id>
      <created_at>sometime</created_at>
      <last_updated>sometime</last_updated>
      <bar>
        ...
      </bar>
      <bar>
        ...
      </bar>
    </foo>

Works great if I copy the content from bar/_bar.xml.builder into the
template, but then things just aren't DRY.

Thanks,

Matthew

-- 
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.

Reply via email to