微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

设计after_sign_in_path_for会产生路由错误

如何解决设计after_sign_in_path_for会产生路由错误

|| 我正在尝试将登录用户重定向到其个人资料页面,但出现以下错误
No route matches {:action=>\"create\",:controller=>\"trooper_profiles\"}
这是我要遵循的指南。 https://github.com/plataformatec/devise/wiki/操作方法:-redirect-to-a-specific-page-on-successful-sign-in 在我的application_controller中,我已添加
def after_sign_in_path_for(resource)
  trooper_trooper_profile_path
end
耙道显示
trooper_trooper_profile POST   /troopers/:trooper_id/trooper_profile(.:format)      {:action=>\"create\",:controller=>\"trooper_profiles\"}
new_trooper_trooper_profile GET    /troopers/:trooper_id/trooper_profile/new(.:format)  {:action=>\"new\",:controller=>\"trooper_profiles\"}
edit_trooper_trooper_profile GET    /troopers/:trooper_id/trooper_profile/edit(.:format) {:action=>\"edit\",:controller=>\"trooper_profiles\"}
GET    /troopers/:trooper_id/trooper_profile(.:format)      {:action=>\"show\",:controller=>\"trooper_profiles\"}
PUT    /troopers/:trooper_id/trooper_profile(.:format)      {:action=>\"update\",:controller=>\"trooper_profiles\"}
DELETE /troopers/:trooper_id/trooper_profile(.:format)      {:action=>\"destroy\",:controller=>\"trooper_profiles\"}
服务器日志
Started POST \"/troopers/login\" for 127.0.0.1 at 2011-05-24 21:11:09 +1000
Processing by Devise::SessionsController#create as HTML
Parameters: {\"utf8\"=>\"✓\",\"authenticity_token\"=>\"LhT6b4xu5bIJ5kwhS74L7dpaGbuR5BTdirh9AziD+Ew=\",\"trooper\"=>{\"email\"=>\"robert@example.com\",\"password\"=>\"[FILTERED]\",\"remember_me\"=>\"0\"},\"commit\"=>\"Sign in\"}
Trooper Load (0.6ms)  SELECT \"troopers\".* FROM \"troopers\" WHERE (\"troopers\".\"email\" = \'robert@example.com\') LIMIT 1
AREL (0.4ms)  UPDATE \"troopers\" SET \"last_sign_in_at\" = \'2011-05-24 11:09:04.931050\',\"current_sign_in_at\" = \'2011-05-24 11:11:09.603249\',\"sign_in_count\" = 44,\"updated_at\" = \'2011-05-24 11:11:09.603773\' WHERE (\"troopers\".\"id\" = 1)
Completed   in 149ms
ActionController::RoutingError (No route matches {:action=>\"create\",:controller=>\"trooper_profiles\"}):
app/controllers/application_controller.rb:18:in `after_sign_in_path_for\'
知道为什么路线不匹配吗?     

解决方法

您没有告诉您的路径助手要显示哪个士兵档案。 尝试这样更改
after_sign_in_path_for
方法:
def after_sign_in_path_for(resource)
  trooper_trooper_profile_path(resource) # Note presence of \'resource\'
end
    ,您正在重定向到发布操作     

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。