简体   繁体   中英

Rails 4 routing with optional params?

I set an optional param in my signup route:

devise_scope :user do
  get '/signin', to: 'devise/sessions#new'
  get '/signup(/:sign_up_key)', to: 'users/registrations#new'
end

Before the optional param was there I could do:

signup_path

Rack routes shows:

signin GET    /signin(.:format)                   devise/sessions#new
       GET    /signup(/:sign_up_key)(.:format)    users/registrations#new

Now signup_path is no longer available? How do I get it back with the optional param there?

By the way I am routing like this:

<%= link_to '/signup' ... %>

Instead of:

<%= link_to signup_path ... %>

Would like to get access to the prefix back? Thanks!

尝试添加as: :singup

get '/signup(/:sign_up_key)', to: 'users/registrations#new', as: :signup

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