未确认时设计重定向到自定义网址而不是闪存通知

时间:2013-05-30 13:48:53

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

使用自定义故障类实现设计用于检测用户是否未确认的触发器是什么? warden_message不起作用。有人知道吗?

class CustomFailure < Devise::FailureApp

  def redirect_url

    if warden_options[:scope] == :user
      new_user_registration_path
    else
      new_user_registration_path
    end
  end

  def respond

    if http_auth?
      http_auth
    else
      store_location!
      flash[:alert] = i18n_message unless flash[:notice]

      if warden_message == :unconfirmed
        redirect_to "/confirm"
      else
        redirect_to sign_in_path
      end
    end

  end

end

1 个答案:

答案 0 :(得分:7)

如果您想将用户重定向到自定义网址,则应该在redirect_url而不是respond中执行此操作:

def redirect_url
  if warden_message == :unconfirmed
    '/confirm'
  else
    new_user_registration_path
  end
end