设计 - 更改路由的名称

时间:2012-02-08 13:26:06

标签: ruby-on-rails authentication devise

默认情况下,Devise会为登录创建一个路由为“/ sign_in”。

我如何更改路径以使其为'/ log_in'?

2 个答案:

答案 0 :(得分:2)

添加范围

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

答案 1 :(得分:0)

这是我最终做到的,因为我已经插入控制器来处理Devise的各个方面:

在routes.rb

#Add Devise authentication to users, handling omniauth callbacks in users/omniauth_callbacks_controller
devise_for :users, :skip => [:sessions],
                   :controllers => { :omniauth_callbacks => 'users/omniauth_callbacks',
                                       :registrations => 'users/registrations'
                                      }

# :skip => [:sessions] tells devise not to create routes for sessions, allowing us to declare our own
as :user do
  get 'users/log_in' => 'devise/sessions#new', :as => :new_user_session
  post 'users/log_in' => 'devise/sessions#create', :as => :user_session
  delete 'users/log_out' => 'devise/sessions#destroy', :as => :destroy_user_session
end