无法登录用户资源 – 设计/ sessionsController #create中的NoMethod错误

我对Rails 3和Devise有一个特殊的问题。 我的Rails应用程序有3种用户类型:
客户,所有者和管理员

routes.rb中:

devise_for :admins devise_for :owners devise_for :clients 

application_controller.rb:

 def after_sign_in_path_for(resource) if resource == "client" "/client_accounts/" + current_client.id.to_s elsif resource == "admin" stored_location_for(:admins) || "/admin/control_panel" elsif resource == "owner" stored_location_for(:owners) || "/client_accounts" end end 

我的登录所有者和管理员工作正常,但我无法让客户登录工作..这是我得到的错误:

 NoMethodError in Devise/sessionsController#create undefined method `client_url' for # 

应用程序跟踪为空。

根据Devise文档 ,after_sign_in_path_for方法接受实际的Client对象,但是您将输入与一组字符串进行比较,这些字符串都将返回false,因此您的big if子句将返回nil。 不确定当发生这种情况时Devise的目的是什么,但寻找’client_url’将是一个合理的默认值。

试试这个:

 def after_sign_in_path_for(resource) case resource when Client then "/client_accounts/" + current_client.id.to_s when Admin then stored_location_for(:admins) || "/admin/control_panel" when Owner then stored_location_for(:owners) || "/client_accounts" end end 

如果这没有帮助,我会在方法的顶部放置一个调试器语句,以确保你的帮助器如’current_client’的行为符合你的预期(并确保完全调用after_sign_in_path_for)。

只是一个想法,但如果您将响应更改为:“/ client_accounts /#{current_client.id.to_s}”会发生什么?

您的佣金路线结果如何?