Dear All, How to export a table data to xml file using Ruby on Rails. I followed this code it''s created xml file like table.Anyone knows please suggest me. Controller headers[''Content-Type''] = "text/xml" headers[''Content-Disposition''] = ''attachment; filename="xml-export.xml"'' headers[''Cache-Control''] = '''' @records = Company.find(:all) View <table border="1"> <th>Name</th> <th>Address1</th> <th>Address2</th> <% @records.each do |c| %> <tr><td><%= c.name %></td> <td><%= c.com_address1 %></td> <td><%= c.com_address2 %></td> </tr> <% end %></table> XML File is - <table border="1"> <th>Name</th> <th>Address1</th> <th>Address2</th> - <tr> <td>xx</td> <td>xx</td> <td>xx</td> </tr> - </table> Regards R.Devi -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Saravanan Krishnan
2009-Jan-31 11:48 UTC
Re: export a table data to xml file using Ruby on Rails
Hi Devi, Try with following codes. let me know if you find any issues def xmlfile @records = Company.find(:all) render :xml=>@records.to_xml end def xmlfile @records = Company.find(:all) render :partial => ''/company/xmlfile'', :layout => false, :content_type => ''application/xml'' end Thanks Saravanan K -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks for updating and it''s working fine. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---