简体   繁体   中英

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

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

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"}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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