ruby-on-rails - rails/设计 : How can I redirect back and show flash messages when registration fails?

标签 ruby-on-rails ruby devise

设计有问题。我有一个包含 token 的注册网址...类似于:localhost:3000/users/sign_up/df293b00ae137b8b6436d45e622304aedc549072

当注册失败(密码不匹配或其他原因)时,应用程序会重定向到 localhost:3000/users 并显示来自模型的正确闪存消息。

但是我需要应用程序使用 token 重定向回 url。所以我将 redirect_to :back 扔到 Controller 中,这让我返回,但闪现消息没有出现。

如何让页面重定向回来(保留准确的 url)并仍然显示闪现消息。

这是来自设备 Controller 的代码:

 def new
    resource = build_resource({})
    respond_with resource
  end

  # 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_up(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

任何帮助都会很棒!

最佳答案

你想要的是为设计编写一个自定义的 FailureApp,它用于在用户不可验证(验证失败)时将用户重定向到给定页面。

您可以在 devise wiki 中查看有关谁编写和使用失败应用程序的更多信息:

https://github.com/plataformatec/devise/wiki/How-To:-Redirect-to-a-specific-page-when-the-user-can-not-be-authenticated

关于ruby-on-rails - rails/设计 : How can I redirect back and show flash messages when registration fails?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14166945/

相关文章:

javascript - Webpacker 未检测到文件 javascript/packs/application.js 中的导入函数

ruby-on-rails - 我可以使用 github-services hook 将我的提要发布到其他服务吗?

ruby-on-rails - 一个月前得到,但总是在一个月的第 15 天

ruby-on-rails - Rails,根据用户类型设计 : Same resource, 不同的 Controller

ruby-on-rails - 在首页上设计注册表格

ruby-on-rails - 无法安装 curl gem

ruby-on-rails - 载波:从 ASCII-8BIT 到 UTF-8 的编码::UndefinedConversionError ("\xFF")

ruby-on-rails - 如何知道要拯救哪些异常?

ruby - 如何在 Ruby 中对零进行四舍五入

ruby-on-rails - 从 Authlogic 迁移到 Devise