I have named routes like these:
product GET /products/:id
formatted_product GET /products/:id.:format
The GET /products and GET /products/:id would render the html listing
of all products and and a specific product id, respectively. I wanted
to place a button link like 'Send XML Data' in the views whenever I
display the listing of products or showing just a page for a specific
I created a 'send_xml_data' action/method in the Products controller
with the intent of giving the user a choice to dowload the xml file of
listing of products or a specifc product using this, thinking that
this would prompt for a download (in this case the whole product
@products = Product.find(:all)
products_file << xml.product_list(:for_product =>
send_data products_file, :filename => 'product_list.xml'
When I created a button link to direct to the products controller and
the action/method send_xml_data, I get this error from the SHOW action
saying that "send_xml_data" is not a valid product id, even if I
enabled in the config\routes.rb the "map.connect ':controller/:action'
route with high priority . I always get routed to the show action GET
It seems like the solution to send an xml file in the controller
defining the following method below will not work.
my_file = <<-FILE
<your file contents here>
send_data my_file, :filename => 'myfile.xml'
Also, the method below will not work beacuse the xml template for a
single product will be dynamic based on the respond_to format. A URL
http://localhost:3000/products/9 or a 9.xml will generate a html file
or an xml file based on the RESTful format.
"send_data render :template=>"/route/gpx.rxml", :filename => "tb.xml"
Is there a way I can code the routing link to from a show product id
template or a listing template to give the user the ability to
download an xml file while at the same time take advantage of named
routes and the existing RESTful ability of the views that already
render xml on the browser?