简体   繁体   English

rails devise-多个注册网址

[英]rails devise - multiple register url

At first I used devise register for one type of user. 最初,我为一种类型的用户使用了设计注册。 Works perfectly well, but now I add 2 specifics routes register/users for lambda users and register/pro for professional. 工作得很好,但现在我加2个具体路线register/users的拉姆达用户和register/pro专业。

Theses two routes uses the same model users, with just changing the form view. 这两个路由使用相同的模型用户,只是更改了表单视图。

But when I submit the form, in case of failure I am redirect to /users/ and nothing else appends. 但是,当我提交表单时,如果失败,我将重定向到/users/并且没有其他内容。

To do that, I have done this : 为此,我已经这样做了:

get '/register', to: 'devise/registrations#new', as: :register # original version
# and added :
get '/register/users', to: 'devise/registrations#new', as: :register_users
get '/register/professional', to: 'devise/registrations#new', as: :register_pro

But, like I said, nothing appends but redirect to /users/ if the form is badly filled. 但是,就像我说的,如果表格填写不正确,则只能追加到/users/

So I also tried to add this : 所以我也尝试添加这个:

post '/register/users' => 'devise/registrations#create', :as => :register
post '/register/professional' =>   'devise/registrations#create', :as => :register

But same result. 但结果相同。

I'm doing something wrong, anybody as an idea? 我做错事了,有人想吗?

Thanks ! 谢谢 !

EDIT : 编辑:

For now, the problem is that in case of badly fill the formulaire,this redirect to ./users and not to register/users . 目前,问题在于,如果公式填写不正确, ./users重定向到./users而不是register/users But in case of succeded, it's working. 但是如果成功,它就可以了。

You need override after_sign_up_path_for in a Controller(usually ApplicationController) 您需要在Controller(通常是ApplicationController)中覆盖after_sign_up_path_for

def after_sign_up_path_for(resource)
  if resource.type == :pro # please modify this line
    some_your_path
  else
    super # this will be /users/
  end
end

I assume you have User model. 我假设您有User模型。 Then this resource is user object. 那么这个resource就是用户对象。 And I assume you have some attribute in User model to find pro/non-pro. 我假设您在用户模型中有一些属性可以查找专业/非专业人士。 Please use that attribute for 'if' statement and write paths. 请将该属性用于'if'语句并编写路径。

If you use Confirmable you need to override after_inactive_sign_up_path_for instead of after_sign_up_path_for . 如果使用Confirmable,则需要覆盖after_inactive_sign_up_path_for而不是after_sign_up_path_for

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM