2011-01-26 63 views
4

如何在使用before_filter時更改設計的登錄路徑:athenticate用戶?更改設計的sign_in url

我在帖子控制器中有以下內容。

如:

class PostsController < ApplicationController 
    before_filter :authenticate_user! 

    def index 
     @posts = Post.all 
    end 
end 

目前,它會自動進入到 '/用戶/ sign_in'

我想使用 '/登錄'

回答

10

使用devise_for方法對現在的人進行排序。

devise_for :users, :controllers => { :registrations => 'registrations' }, :path => 'accounts', :path_names => { :sign_in => 'login', :sign_up => 'new', :sign_out => 'logout', :password => 'secret', :confirmation => 'verification' } 

所以現在sign_in路徑是「賬戶/登錄」

+1

我認爲如果你添加一個前綴斜槓(` :path =>'/'`)作爲它將使用根url的路徑。但我不確定,因爲我對Rails 3中的路由沒有信心。 – 2012-04-18 12:42:41

1

我覺得你的信息尋找的是在這裏:https://github.com/plataformatec/devise/wiki/How-To:-Change-the-default-sign_in-and-sign_out-routes

被盜從文檔:

devise_scope :user do 
    get "/login" => "devise/sessions#new" 
end 

在你的情況下,你會使用:後,而不是:我相信用戶。 它遲到了,我很模糊,但我認爲應該這樣做。

+0

感謝邁克雖然這種解決辦法不修改sign_in資源路徑。然而,我通過devise_for方法進行了整理。例如: devise_for:users,:controllers => {:registrations =>'registrations'},:path =>'accounts',:path_names => {:sign_in =>'login',:sign_up =>'new' ,:sign_out =>'logout',:password =>'secret',:confirmation =>'verification'} 所以現在sign_in路徑是'accounts/login' – onepixelsolid 2011-01-29 11:37:19

2

該解決方案不會修改sign_in資源路徑。

但是我通過devise_for方法對它進行了整理。例如:

devise_for :users, 
      :controllers => { :registrations => 'registrations' }, 
      :path => 'accounts', 
      :path_names => { :sign_in => 'login', 
          :sign_up => 'new', 
          :sign_out => 'logout', 
          :password => 'secret', 
          :confirmation => 'verification' } 

所以現在sign_in路徑是「賬戶/登錄」