简体   繁体   中英

Changing the sign_in url for Devise

How do you change the sign in path for Devise when using a before_filter :athenticate user?

I have the following in a Posts controller.

eg:

class PostsController < ApplicationController
    before_filter :authenticate_user!

    def index
        @posts = Post.all
    end
end

At the moment it automatically goes to '/users/sign_in'

I'd like to use '/login'

Sorted for now folks, using the devise_for method.

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

So now the sign_in path is 'accounts/login'

That solution doesn't modify the resource path for sign_in.

I did however sort it out via the devise_for method. eg:

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

So now the sign_in path is 'accounts/login'

I think the info you are looking for is here: https://github.com/plataformatec/devise/wiki/How-To:-Change-the-default-sign_in-and-sign_out-routes

Stolen from the docs:

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

In you case you would use :post instead of :user I believe. Its late and I am fuzzy headed but I think that should do it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM