使用`:as`选项具有相同名称的路由 - 设计自定义路径

时间:2017-07-31 06:55:03

标签: ruby-on-rails devise

我尝试使用自定义路径进行注册和与Devise的会话。

我的问题是路线不能有'as'

我的代码是:

 #Devise
  devise_for :users, skip: [:sessions,:registration]

  as :user do
    get 'signup', to: 'users/registrations#new', as: :new_user_registration
    post 'signup', to: 'users/registrations#create', as: :user_registration
    get 'edit', to: 'users/registrations#edit', as: :edit_user_registration
    put 'edit', to: 'users/registrations#update' , as: :user_registration
    get 'signin', to: 'users/sessions#new', as: :new_user_session
    post 'signin', to: 'users/sessions#create', as: :user_session
    delete 'signout', to: 'users/sessions#destroy', as: :destroy_user_session
  end

put'edit'的{​​{1}}请求必须与帖子具有相同的as:

,如何才能看到问题

我该如何解决这个问题?一场比赛?

2 个答案:

答案 0 :(得分:1)

devise_for :users, skip: [:sessions, :registrations, :passwords]

devise_scope :user do
# sessions


get    'login',  to: 'devise/sessions#new',     as: :new_user_session
  post   'login',  to: 'devise/sessions#create',  as: :user_session
  delete 'logout', to: 'devise/sessions#destroy', as: :destroy_user_session
  # registrations
  put    '/account',  to: 'devise/registrations#update'
  delete '/account',  to: 'devise/registrations#destroy'
  post   '/account',  to: 'devise/registrations#create'
  get    '/register', to: 'devise/registrations#new',    as: :new_user_registration
  get    '/account',  to: 'devise/registrations#edit',   as: :edit_user_registration
  patch  '/account',  to: 'devise/registrations#update', as: :user_registration
  get    '/account/cancel', to: 'devise/registrations#cancel', as: :cancel_user_registration# passwords 
  # passwords
  get   'new-pass',  to: 'devise/passwords#new',    as: :new_user_password
  get   'edit-pass', to: 'devise/passwords#edit',   as: :edit_user_password
  patch 'edit-pass', to: 'devise/passwords#update', as: :user_password
  post  'new-pass',  to: 'devise/passwords#create', as: :user_password
end

检查以下代码以自定义设计路线

答案 1 :(得分:0)

根据命名惯例,您的patch/put助手应该已经命名为user_registration,而post助手应该命名为user_registrations,也就是说以复数形式。 请查看http://guides.rubyonrails.org/routing.html#resource-routing-the-rails-default以更加自信地路由DSL和路由约定。