【问题标题】:devise redirect to a custom url when not confirmed instead of flash notice在未确认时设计重定向到自定义 URL,而不是 Flash 通知
【发布时间】:2013-06-03 04:00:45
【问题描述】:

实现了自定义失败类,以设计检测用户是否未确认的触发器是什么? 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

【问题讨论】:

  • 所以?问题是什么?你得到一个错误还是什么?
  • @phoet 它不再重定向,确认路径永远不会路由到
  • 你做了什么调试?

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


【解决方案1】:

如果您想将用户重定向到自定义 URL,您应该在 redirect_url 中进行,而不是在 respond 中进行:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-31
    • 2015-01-05
    • 2012-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多