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

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – Rails 3覆盖Devise会话控制器前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我需要在登录过程中重写Devise会话控制器(Rails 3.0.9,Ruby 1.9.2,Devise 1.3.4),我试过这个没有任何影响
  1. class SessionsController < Devise::SessionsController
  2.  
  3. # GET /resource/sign_in
  4. def new
  5. resource = build_resource
  6. clean_up_passwords(resource)
  7. respond_with_navigational(resource,stub_options(resource)){ render_with_scope :new }
  8. end
  9.  
  10. end

想法?

编辑
如答案所示,我还需要改变路线.另外,我还需要复制视图.这里有更好的解释
http://presentations.royvandewater.com/authentication-with-devise.html#8

我的自定义策略:

  1. devise.rb
  2. config.warden do |manager|
  3. manager.strategies.add(:custom_strategy) do
  4. def authenticate!
  5. ... authenticate against 3rd party API...
  6. if res.body =~ /success/
  7. u = User.find_or_initialize_by_email(params[:user][:email])
  8. if u.new_record?
  9. u.save
  10. end
  11. success!(u)
  12. end
  13. end
  14. end

解决方法

您是否改变了使用新控制器的路线?
  1. /config/routes.rb
  2.  
  3. devise_for :users,:controllers => {:sessions => "sessions"}

猜你在找的Ruby相关文章