I have a Rails route that takes stock ticker symbols as the :id
feeds/AMZN
will return a page for Amazonfeeds/AMZN.csv
will ret
I ran into this while patching the RubyGems API recently (trying to access the flickr.rb
using the API (/api/v1/gems/flickr.rb.json
) was not working).
The trick was to supply the route with a regexp to handle the :id
parameter, and then specify valid :format
. Keep in mind that the :id
regexp needs to be "lazy" (must end with a question mark), otherwise it will eat the .csv
and assume that it's part of the id. The following example would allow JSON, CSV, XML, and YAML formats for an id with a period in it:
resources :feeds, :id => /[A-Za-z0-9\.]+?/, :format => /json|csv|xml|yaml/