2011-11-09 29 views
8

我需要在登錄過程(3.0.9導軌,紅寶石1.9.2,1.3.4設計)來覆蓋設計會話控制器,我想這沒有任何效果導軌3倍率設計會話控制器

class SessionsController < Devise::SessionsController 

    # GET /resource/sign_in 
    def new 
    resource = build_resource 
    clean_up_passwords(resource) 
    respond_with_navigational(resource, stub_options(resource)){ render_with_scope :new } 
    end 

end 

想法?

編輯 正如答案中所示,我還需要更改路線。另外,我還需要複製視圖。這是更好地在這裏 http://presentations.royvandewater.com/authentication-with-devise.html#8

我的自定義策略解釋說:

devise.rb 
config.warden do |manager| 
    manager.strategies.add(:custom_strategy) do 
    def authenticate! 
     ... authenticate against 3rd party API... 
     if res.body =~ /success/ 
     u = User.find_or_initialize_by_email(params[:user][:email]) 
     if u.new_record? 
      u.save 
     end 
     success!(u) 
    end 
    end 
end 

回答

13

你有你的改變,使用新控制器的路線?

/config/routes.rb 

    devise_for :users, :controllers => {:sessions => "sessions"} 
+0

是的我只是想到了這一點,我也需要複製它看起來的意見。除了上述變更之外,我是否還保留了原始的'devise_for:users'路線?我不想覆蓋其他行動。 –

+0

還有一個問題,除了我添加的自定義策略之外,它也不會執行默認的數據庫身份驗證策略,不確定如何解決此問題。 –

+0

應該只有1個'devise_for',並且在您複製視圖之後,即使您沒有覆蓋的操作也應該可以工作。 至於你的其他問題,我並不完全關注。你有你的模型中設置的':database_authenticatable'選項。 (即:devise:database_authenticatable) – Olives