Rails 4使用可选参数进行路由?

时间:2014-08-14 17:08:55

标签: ruby-on-rails ruby ruby-on-rails-4

我在注册路径中设置了一个可选的参数:

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

在可选参数之前,我可以做到:

signup_path

机架路线显示:

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

现在signup_path已不再可用?如何使用可选参数将其恢复?

顺便说一下,我这样路由:

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

而不是:

<%= link_to signup_path ... %>

想获得前缀的访问权限吗?谢谢!

1 个答案:

答案 0 :(得分:2)

尝试添加as: :singup

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