How can I set default parameter value in routing i

2019-04-18 00:39发布

问题:

How can I set default parameter value in routing in Rails 3. For example I have this route

match ':slug/:id/:direction' => 'quiz#show', :as => :quiz_details, :direction => "next"

and I want to default the value of direction to next.

回答1:

match ':slug/:id/:direction' => 'quiz#show', :as => :quiz_details, :defaults => { :direction => "next" }

More details in the official Rails guides.