Custome render xml

13 views
Skip to first unread message

M.SH

unread,
Apr 3, 2012, 11:18:47 AM4/3/12
to rubyonra...@googlegroups.com
i want to make render xml for an complex object
ex
      make render :xml => posters
poster = [name, post_id,created_at, ....]
post = [title, body,created_at, ....]

and i want the render output to be

<posters>
    <poster>
        <name>
            name
        </name>
        <post>
            <title>
                title
            </title>
            <body>
                body
            </body>
        </post>
        ...
        ...
    </poster>
    ...
    ...
</posters>

thanks in advance
M.SH

Peter Vandenabeele

unread,
Apr 3, 2012, 11:51:56 AM4/3/12
to rubyonra...@googlegroups.com

You could have in your ../app/views/posters/
a file

index.xml.builder

which may be automatically called when the
request needs to render XML. The file
could start like this:

xml.instruct!
xml.posters do
@posters.each do |poster|
xml.poster(...
...
end
end
end

Check out Google for "xml builder Ruby"
and this project from Jim Weirich.

https://github.com/jimweirich/builder

HTH,

Peter

محمد شحاته

unread,
Apr 3, 2012, 1:17:48 PM4/3/12
to rubyonra...@googlegroups.com
Thank u very much , that is what i need :)


--
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 rubyonra...@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-ta...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.




--
-------------------------
محمد شحاته
4th year
Computer and Systems Department
Alexandria University
Egypt

Reply all
Reply to author
Forward
0 new messages