Rails Devise防止在注册后立即登录而不使用Confirmable

时间:2012-09-22 06:10:48

标签: ruby-on-rails devise devise-confirmable

用例:

  1. 管理员应该能够创建用户,并且不应该尝试登录。
  2. 公共用户可以创建帐户,注册后他应该被重定向到登录页面,而不是立即签名。
  3. 有人可以帮我吗?

    谢谢:)

1 个答案:

答案 0 :(得分:6)

您需要做的是覆盖Devise的RegistrationsController创建方法。

如何做到here有一个很好的解释。

这是Devise创建动作:

  # POST /resource
  def create
    build_resource

    if resource.save
      if resource.active_for_authentication?
        set_flash_message :notice, :signed_up if is_navigational_format?
        sign_in(resource_name, resource)
        respond_with resource, :location => after_sign_up_path_for(resource)
      else
        set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_navigational_format?
        expire_session_data_after_sign_in!
        respond_with resource, :location => after_inactive_sign_up_path_for(resource)
      end
    else
      clean_up_passwords resource
      respond_with resource
    end
  end

覆盖控制器后,只需删除sign_in(resource_name, resource)

即可

您还可以设置方法after_sign_up_path_for(resource)以满足您的需求