简体   繁体   中英

Redirect dynamic routes in Rails

How can I redirect

get '/directory/:alphabet' => redirect('/directory/:alphabet/1') , :constraints => { :alphabet => /[A-Za-z#]/}

This throws an error about alphabet. How do I use the value that I get ?

See "dynamic segments" under http://guides.rubyonrails.org/routing.html#redirection

Use %{alphabet} to read the value from the source

get '/directory/:alphabet' => redirect('/directory/%{alphabet}/1') , :constraints => { :alphabet => /[A-Za-z#]/}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM