2012-02-14 12 views

Odpowiedz

62

Jest w lib/devise/controllers/helpers.rb1 i jest generowana dynamicznie (użytkownik jest tylko jednym z możliwych przyrostków):

def self.define_helpers(mapping) #:nodoc: 
    mapping = mapping.name 

    class_eval <<-METHODS, __FILE__, __LINE__ + 1 
     def authenticate_#{mapping}!(opts={}) 
     opts[:scope] = :#{mapping} 
     warden.authenticate!(opts) if !devise_controller? || opts.delete(:force) 
     end 

     def #{mapping}_signed_in? 
     !!current_#{mapping} 
     end 

     def current_#{mapping} 
     @current_#{mapping} ||= warden.authenticate(:scope => :#{mapping}) 
     end 

     def #{mapping}_session 
     current_#{mapping} && warden.session(:#{mapping}) 
     end 
    METHODS 

    ActiveSupport.on_load(:action_controller) do 
     helper_method "current_#{mapping}", "#{mapping}_signed_in?", "#{mapping}_session" 
    end 
    end 
+0

Proszę zobaczyć http://stackoverflow.com/questions/32237346/what-is-code-for-devise-authenticate-user-after-generated-for-user – Abram

+1

, więc jak mam do niego dostęp explicity. to połączenie nie działa >> 'Devise :: Controllers :: Helpers.authenticate_user!' – vipin8169

19

Po dodaniu opracować do tory, zazwyczaj dodaje się config/routes.rb:

devise_for :user 

Jest to zdefiniowane w Devise Mapper class.

który nazywa Devise.add_mapping dla każdego zasobu przechodzi do devise_for

metoda add_mapping modułu opracowują jest zdefiniowana here, które następnie wywołuje define_helpers, który definiuje authenticate jak omówiono w innych odpowiedzi.

Powiązane problemy