加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – Rails 3覆盖Devise会话控制器

发布时间:2020-12-16 19:16:19 所属栏目:百科 来源:网络整理
导读:我需要在登录过程中重写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) r
我需要在登录过程中重写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

想法?

编辑
如答案所示,我还需要改变路线.另外,我还需要复制视图.这里有更好的解释
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

解决方法

您是否改变了使用新控制器的路线?
/config/routes.rb

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读