Ruby on rails 设计错误重定向到错误表单

Ruby on rails 设计错误重定向到错误表单,ruby-on-rails,ruby-on-rails-4,devise,Ruby On Rails,Ruby On Rails 4,Devise,我刚刚注意到,当抛出验证错误时,我的Desive注册表单有一个问题 我有两种表格,一种是个人的,另一种是公司的,来区分这两种 <p><%= link_to 'Sign Up as Individual', new_user_registration_path %></p> <p><%= link_to 'Sign Up as Vets/Rescue Centre', new_user_registration_path(organizatio

我刚刚注意到,当抛出验证错误时,我的Desive注册表单有一个问题

我有两种表格,一种是个人的,另一种是公司的,来区分这两种

<p><%= link_to 'Sign Up as Individual', new_user_registration_path %></p>
<p><%= link_to 'Sign Up as Vets/Rescue Centre', new_user_registration_path(organization: true) %></p>

看法


当公司注册表单验证失败时,它会将我重定向到个人注册表单(这是新用户注册的默认url)

有没有办法告诉表单重定向到正在使用的表单

编辑

我已覆盖注册控制器中的一个方法

class RegistrationsController < Devise::RegistrationsController
  protected

  def after_sign_up_path_for(resource)
   administration_index_path
  end
end
class Users::RegistrationsController < Devise::RegistrationsController
  def create
    build_resource(sign_up_params)
    resource_saved = resource.save
    yield resource if block_given?
    if resource_saved
      if resource.active_for_authentication?
        set_flash_message :notice, :signed_up if is_flashing_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_flashing_format?
        expire_data_after_sign_in!
        respond_with resource, location: after_inactive_sign_up_path_for(resource)
      end
    else
      clean_up_passwords resource
      @validatable = devise_mapping.validatable?
      if @validatable
        @minimum_password_length = resource_class.password_length.min
      end
      if resource.is_a? Organization
        redirect_to new_user_registration_path(organization: true)
      else
        redirect_to new_user_registration_path
      end
    end
  end
end
类注册控制器
这会引起问题吗


感谢

对于自定义重定向,您必须覆盖注册\u控制器上的创建操作

class RegistrationsController < Devise::RegistrationsController
  protected

  def after_sign_up_path_for(resource)
   administration_index_path
  end
end
class Users::RegistrationsController < Devise::RegistrationsController
  def create
    build_resource(sign_up_params)
    resource_saved = resource.save
    yield resource if block_given?
    if resource_saved
      if resource.active_for_authentication?
        set_flash_message :notice, :signed_up if is_flashing_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_flashing_format?
        expire_data_after_sign_in!
        respond_with resource, location: after_inactive_sign_up_path_for(resource)
      end
    else
      clean_up_passwords resource
      @validatable = devise_mapping.validatable?
      if @validatable
        @minimum_password_length = resource_class.password_length.min
      end
      if resource.is_a? Organization
        redirect_to new_user_registration_path(organization: true)
      else
        redirect_to new_user_registration_path
      end
    end
  end
end

您是否覆盖了Desive registration controller?我唯一覆盖的是(资源)的注册后路径,但在这两种情况下,您的资源都是用户。所以你必须覆盖注册控制器。您没有注册控制器。是吗?我不知道在这里要覆盖什么,请你给我指一下正确的方向好吗?你需要覆盖Desive的注册来处理这个案子谢谢,它不喜欢这个组织,验证失败时的未初始化常量错误这取决于您如何实现组织和个人之间的差异…他们都是用户,但作为公司(组织)的用户有一个db列company_表单,其标志设置为true。。organization=true用于加载公司的注册表格。。这有意义吗?为什么是用户/注册,而不仅仅是注册?感谢您可以将条件更改为resource.company\form设置用户目录是有意义的,因为您经常需要覆盖designe controllers,这有助于保持controllers目录干净