Ruby on rails 如何使用Desive在两个不同的页面中注册
我在登录系统中使用了Desive。我想在注册下创建两个新的html,这是两个不同角色的页面。我想通过选择registrations/new中的角色进入该页面,这是原始注册文件。接下来我该怎么办 我的文件在视图/用户/注册中的顺序:Ruby on rails 如何使用Desive在两个不同的页面中注册,ruby-on-rails,devise,Ruby On Rails,Devise,我在登录系统中使用了Desive。我想在注册下创建两个新的html,这是两个不同角色的页面。我想通过选择registrations/new中的角色进入该页面,这是原始注册文件。接下来我该怎么办 我的文件在视图/用户/注册中的顺序: edit.html.erb new.html.erb new_librarian.html.erb new_student.html.erb 我想通过registrations/new在新的两页中注册 注册 注册为学生“获取”%> 注册为图书管理员“获取”%>
- edit.html.erb
- new.html.erb
- new_librarian.html.erb
- new_student.html.erb
注册
注册为学生“获取”%>
注册为图书管理员“获取”%>
注册
(最少字符)
获取“用户/注册/新图书管理员”
获取“用户/注册/新学生”
您可以通过覆盖“设计注册”控制器来实现这一点。在覆盖的注册控制器中,在保存用户后的新方法中
#app/config/routes.rb
为:用户,:控制器=>{:注册=>“注册”}
#app/controllers/registrations_controller.rb
类注册控制器<设计::注册控制器
def新
如果@user.save!
如果@user.role==“图书管理员”
重定向到图书管理员档案路径
elsif@user.role==“学生”
重定向到学生档案路径
结束
结束
结束
结束
您可以在路由中定义librarian\u profile\u path
和student\u profile\u path
#app/config/routes.rb
获取“图书管理员/新”=>“图书管理员档案#新”,:as=>“图书管理员档案”
获取'student/new'=>'student#u profile#new',:as=>'student#u profile'
Could not find devise mapping for path "/users/registrations/new_student". This may happen for two reasons:
1) You forgot to wrap your route inside the scope block. For example: devise_scope :user do get "/some/route" => "some_devise_controller" end
2) You are testing a Devise controller bypassing the router. If so, you can explicitly tell Devise which mapping to use: @request.env["devise.mapping"] = Devise.mappings[:user]