MIME Types and url_for in Rails

I have a nice RESTful controller in my Rails application that uses responds_to to distinguish between requests for HTML and CSV requests, serving the HTML if one uses the URL normally, and the CSV if one adds ".csv" to the end of the URL.

In my view layer ERB file, I want to have a link to the CSV. I could just get the URL for the appropriate action normally and then just add ".csv" to the end of it, but that seems kinda hacky. I don't, however, see anthing in the url_for docs that would allow me to do this more cleanly.

Is there something I'm missing, or am I just stuck with something like this?

<a href="<%= url_for @topic%>.csv">Download CSV</a>

Thanks for any insight!


url_for @topic, :format => :csv

is probably what you are looking for

Need Your Help

Java Eclipse OS Error

java eclipse operating-system

For some reason, Eclipse throws a casting compile error (incorrectly) on a line of code when it is being edited on a mac or linux machine, but causes no such problems on a Windows machine running

jQuery not recognizing <embed> element in IE

javascript jquery flash internet-explorer

I have a CMS where people can paste the code to embed a YouTube video. The problem is, the CMS uses jQuery lightboxes as modal popups to edit things, and the YouTube embeds are appearing over top o...