0
使用Devise并希望用户在注册后转到特定页面。这是踢球者;用户可以通过单选按钮注册为买方或工作人员。当他们注册为工人时,我希望他们去特定的路径。Ruby on Rails:在注册Worker角色后设计重定向
到目前为止,我现在的代码,买方和工人都将走到同一条路径。 'current_user.worker?'代码是我认为不正确的。
new.html.erb
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
<%= radio_button_tag 'user[role]', 'worker' %>
<%= radio_button_tag 'user[role]', 'buyer' %>
<%= f.text_field :username %>
<%= f.email_field :email %>
<%= f.password_field :password %>
<%= f.password_field :password_confirmation %>
<%= f.submit 'Create Account', :class => 'button' %>
<% end %>
application_controller.rb
class ApplicationController < ActionController::Base
def after_sign_up_path_for(resource_or_scope)
if current_user.worker?
account_setup_path
else
end
end
end
你应该在用户模型中有一个名为worker的方法,就像这个'def worker?角色=='工人'结束' – cristian 2011-12-21 10:10:32
嘿@八达通保罗,是的。作为def worker,我在user.rb中拥有该方法?返回角色=='worker'end – 2011-12-21 10:13:02
你测试过了吗?方法来查看它返回所需的结果? – cristian 2011-12-21 10:24:07