设计 - 重定向用户干预视图签约后
问题描述:
当设计用户注册,我需要他重定向到一个视图,在那里他可以选择他想,喜欢什么样的用户:设计 - 重定向用户干预视图签约后
link_to 'TypeA', new_type_a_path
。
link_to 'TypeB', new_type_b_path
。
link_to 'TypeC', new_type_c_path
。
如何配置路由?我知道我可以使用:
class Users::RegistrationsController < Devise::RegistrationsController
protected
def after_sign_up_path_for(resource)
signed_in_root_path(resource)
end
但它已经有一段时间我在RoR工作,所以不记得 - 我应该创建一个控制器对此有何看法?
答
您可以创建一个视图,在其中放置三个链接,以便用户可以选择。
的after_sign_up_path_for
助手方法允许你指定一个URI或路由前缀,这样你就可以创建该视图条目,并使用它的那个方法,如:
# views/registrations/choices.html.erb
<%= link_to 'TypeA', new_type_a_path %>
<%= link_to 'TypeB', new_type_b_path %>
<%= link_to 'TypeC', new_type_c_path %>
# config/routes.rb
get 'choose', to: 'registrations_controller#choices', as: :choices
# registrations_controller.rb
def after_sign_up_path_for(resource)
choices_path
end