我刚刚注意到,当一个验证错误被抛出时,我的设备注册表单出现了问题
我有两种表格,一种是个人表格,另一种是公司表格,以区分两种
<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>
查看
<% if params[:organization] %>
<%= render 'shared/company_signup_form' %>
<% else %>
<%= render 'shared/individual_signup_form' %>
<% end %>
当company_signup_form验证失败时,它会将我重定向到individal_signup_form(这是新用户注册的默认url)
有没有一种方法可以告诉表单重定向到正在使用的表单?
编辑
我已经覆盖了注册控制器中的一个方法
class RegistrationsController < Devise::RegistrationsController
protected
def after_sign_up_path_for(resource)
administration_index_path
end
end
这会在这里引起问题吗?
感谢
对于自定义重定向,您必须覆盖registrations_controller 上的创建操作
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
编辑
您需要配置设计路线:
devise_for :users, controllers: { registrations: 'users/registrations' }