1

我正在运行 Rails 3.2.12 和 Devise 3.1,并且在 routes.rb 中有这个:

devise_for :users do
  get '/login'    => 'devise/sessions#new', as: :login
  get '/logout'   => 'devise/sessions#destroy', as: :logout
end

然而,当我打

127.0.0.1:3000/login

我明白了

No route matches [GET] "/login"

有效的是

127.0.0.1:3000/users/login

我还需要做什么才能跳过输入 /users/ 部分吗?

谢谢!

4

2 回答 2

1
devise_for :users, :path => '', :path_names => { :sign_in => 'login'}

有关在此 StackOverflow 帖子上自定义设计路径的好信息:)


这是一些适用于我们的实时应用程序之一的实时代码:

  #User Management (Devise)
  devise_for :users, :path => '', :controllers => {:sessions => 'sessions', :registrations => 'registrations'}, :path_names => { :sign_in => 'login', :password => 'forgot', :confirmation => 'confirm', :unlock => 'unblock', :registration => 'register', :sign_up => 'new', :sign_out => 'logout'}
  as :user do
    get 'register', :to => 'devise/registrations#new'
    delete 'logout', :to => 'sessions#destroy'
  end
于 2013-10-08T09:36:33.697 回答
0
devise_scope :user do
  get "/login" => "devise/sessions#new"
end

有关更多详细信息,请参阅

于 2013-10-08T09:33:43.813 回答