XML in Rails

1 view
Skip to first unread message

bmcc

unread,
Sep 24, 2009, 4:39:08 PM9/24/09
to Orlando Ruby Users Group Discussion
Hello All:

I have a general question on XML in rails. I know how to return an XML
view for the cleint to render but what if I dont want to render the
XML that is created? What if I want an XML file to be generated and
saved into a folder (through file IO.)

I know this will generate an XML view if the client requests for an
XML formatted document:

respond_to do |format|
format.html
format.xml { render :layout => false }
end

This works if I have an xml builder template available.

This just outputs a view with every column in XML without a builder
template

@product = Product.find(params[:id])
@orders = @product.orders

respond_to do |format|
format.html
format.xml { render :layout => false , :xml =>
@product.to_xml(:include => :orders) }
end

But I dont want to render the XML. I want to save out a file of a
partictular model in XML format and allow Flash to take that XML and
do its own rendering. Can someone give me some insight on this.

Thanks

Justin Blake

unread,
Sep 24, 2009, 10:57:29 PM9/24/09
to Orlando Ruby Users Group Discussion
Can you feed the Flash a URL instead of a path to a real file?

Otherwise you can save the xml to a file just like you'd write any
other file in ruby. Something like File.open('/path/to/file', 'w') { |
f| f.puts @product.to_xml } should do the trick.

--
Justin Blake
http://blog.adsdevshop.com

bmcc

unread,
Sep 25, 2009, 9:06:03 AM9/25/09
to Orlando Ruby Users Group Discussion
Yes that is correct I came to that conclusion right after I started
this thread.

Thanks for the help Justin.


On Sep 24, 10:57 pm, Justin Blake <jbl...@gmail.com> wrote:
> Can you feed the Flash a URL instead of a path to a real file?
>
> Otherwise you can save the xml to a file just like you'd write any
> other file in ruby. Something like File.open('/path/to/file', 'w') { |
> f| f.puts @product.to_xml } should do the trick.
>
> --
> Justin Blakehttp://blog.adsdevshop.com
> > Thanks- Hide quoted text -
>
> - Show quoted text -
Reply all
Reply to author
Forward
0 new messages