设计authenticate_user!不正常

时间:2013-07-30 17:34:43

标签: ruby-on-rails devise

这是我的自定义注册控制器:

class RegistrationsController < Devise::RegistrationsController
  def create
    build_resource

    if resource.valid? && resource.save_with_subscription
      set_flash_message :notice, :signed_up if is_navigational_format?
      sign_in resource_name, resource
      WelcomeMailerWorker.perform_async(resource.id)
      return render json: { success: true, path: after_sign_up_path_for(resource) }
    else
      clean_up_passwords(resource)
      return render json: { success: false, errors: resource.errors.full_messages.to_sentence }
    end
  end

  def destroy
    current_user.soft_delete
    Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name)
    set_flash_message :notice, :destroyed if is_navigational_format?
    respond_with_navigational(resource){ redirect_to after_sign_out_path_for(resource_name) }
  end

  def after_sign_up_path_for(resource)
    return finalize_profile_path if resource.athlete?
    return root_path if resource.college_coach?
  end

  def check_username
    @user = User.find_by_username(params[:username])
    return render text: @user.nil?
  end
end

路线:

  devise_for :users, skip: :registrations, controllers: { sessions: "sessions", passwords: "passwords" }
  devise_for :athletes, skip: [:sessions, :passwords], controllers: { registrations: "registrations" }
  devise_for :coaches, skip: [:sessions, :passwords], controllers: { registrations: "registrations" }

当用户被重定向到finalize_profile_path时,authenticate_user!方法因某种原因返回401未授权

我做了一些进一步的调试,看来Devise在注册后根本没有登录用户

0 个答案:

没有答案
相关问题