Routing with an optional parameter

前端 未结 1 651
小蘑菇
小蘑菇 2020-12-25 09:26

I added in the route file:

map.show_book \"/show_book/:name/year/:year\", :controller => \"book\", :action => \"show_version\"

I also

相关标签:
1条回答
  • 2020-12-25 10:00

    Put the optional parts between parenthesis:

    map.show_book "/show_book/:name(/year/:year)", :controller => "book", :action => "show_version"
    

    and remove the second route.

    Update

    The above answer is only for rails 3 and above. Inverting the two routes definitions fixed the problem (see Alessandro's comment below).

    0 讨论(0)
提交回复
热议问题