Rails 3覆盖Devise会话控制器 [英] Rails 3 override Devise sessions controller
本文介绍了Rails 3覆盖Devise会话控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在登录过程中重写Devise会话控制器(Rails 3.0.9,Ruby 1.9.2,Devise 1.3.4),我没有任何效果地尝试这个。
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
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
推荐答案
您是否改变了路由以使用新的控制器?
Have you altered your route to use your new controller?
/config/routes.rb
devise_for :users, :controllers => {:sessions => "sessions"}
这篇关于Rails 3覆盖Devise会话控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文