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
精彩评论