Need a Rails route with a possible period in the :id, but also retain the optional :format

前端 未结 3 1671
野的像风
野的像风 2021-02-01 05:10

I have a Rails route that takes stock ticker symbols as the :id

  • feeds/AMZN will return a page for Amazon
  • feeds/AMZN.csv will ret
3条回答
  •  难免孤独
    2021-02-01 05:58

    I ran into this as well, but in the reverse direction. (url_for() produces "No route matches" only for IDs with . in them.)

    I'm using match instead of resources to allow some name munging. If you're doing the same, this is what the fix looks like:

    match "feeds/:id" => "stocks#feed", :constraints => {:id => /[\w.]+?/, :format => /html|csv/}
    

提交回复
热议问题