编辑设计失败的注册路径 - Rails

时间:2012-08-02 12:51:04

标签: ruby-on-rails devise routes registration

我一直在搜索有关如何在注册失败后编辑注册路径的文档。

我的网站索引页面上有我的注册表单。在注册失败时,它会重定向到new_user_registration_path而不是用户所在的root。我该如何更新?

2 个答案:

答案 0 :(得分:1)

我已经能够使用customfailure app

为注册表单实现此目的
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
      redirect
    end
  end

  def redirect
    store_location!
    flash[:alert] = i18n_message unless flash[:notice]
    redirect_to '/'
  end
end

当然可以使用类似的选项,这不需要覆盖设计注册控制器吗?

答案 1 :(得分:0)

您可以从here

复制设计注册控制器

您应该可以添加以下内容:

if resource.save
    #handle this 
else 
    #handle this
    redirect_to new_user_registration_path
end

然后在你的路线中:

  devise_for :users, :controllers => {:registrations => 'registrations'}

我不确定如何在不覆盖控制器的情况下执行此操作

相关问题