简体   繁体   English

Rails 3覆盖Devise会话控制器

[英]Rails 3 override Devise sessions controller

I need to override Devise sessions controller during the login process (Rails 3.0.9, Ruby 1.9.2, Devise 1.3.4), I tried this without any effect 我需要在登录过程中重写Devise会话控制器(Rails 3.0.9,Ruby 1.9.2,Devise 1.3.4),我尝试了这个没有任何影响

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

Ideas? 想法?

EDIT As indicated in the answer, I also need to change the route. 编辑如答案所示,我还需要改变路线。 In addition, I also need to copy the views. 另外,我还需要复制视图。 It's better explained here http://presentations.royvandewater.com/authentication-with-devise.html#8 这里有更好的解释http://presentations.royvandewater.com/authentication-with-devise.html#8

My custom strategy: 我的自定义策略:

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

Have you altered your route to use your new controller? 您是否改变了使用新控制器的路线?

/config/routes.rb

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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