سؤال

I am having trouble getting sign ins to work with devise.

So... this is what is getting posted to my sign in action:

Started POST "/sign_in" for 127.0.0.1 at 2011-12-30 17:53:14 +0800
  Processing by UsersController#sign_in as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"k/z12JAUDjFaLtw6X+dL5xa7ZtcLKYmxGSc6SAvaFlE=", "user"=>{"email"=>"fivetwentysix@gmail.com", "password"=>"[FILTERED]", "remember_me"=>"0"}, "x"=>"0", "y"=>"0"}
Completed 401 Unauthorized in 0ms
  Processing by UsersController#new as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"k/z12JAUDjFaLtw6X+dL5xa7ZtcLKYmxGSc6SAvaFlE=", "user"=>{"email"=>"fivetwentysix@gmail.com", "password"=>"[FILTERED]", "remember_me"=>"0"}, "x"=>"0", "y"=>"0"}
Rendered users/new.html.haml within layouts/application (31.7ms)
Completed 200 OK in 40ms (Views: 38.8ms | ActiveRecord: 0.9ms)

Here's what I've tried but doesn't work...

 def sign_in
   authenticate_user!
   if signed_in?
     redirect_to root_path
   else
     redirect_to sign_in_path
   end
 end

So I think I'm missing an understanding of how all this "magic" from devise is suppose to work. Things seem a bit too abstract that I feel isolated from the business logic behind devise, which leaves me lost because I'm unsure on how to tell authenticate_user! to read from my parameters.

So my instinct tells me to look up authenticate_user!

But where is that defined?

I had a brief look in the documentation of devise but could not find that method defined there.

لا يوجد حل صحيح

نصائح أخرى

If you want to use your own redirects after login/logout or edit profile (if I have understood what you meant), I suggest using this kind of method :

class ApplicationController < ActionController::Base
  private

  def after_sign_out_path_for(resource_or_scope)
    root_path
  end

  def after_sign_in_path_for(resource_or_scope)
    root_path
  end

  def after_update_path_for(resource_or_scope)
    root_path
  end
end
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top