设计after_sign_in_path_for生成路由错误

发布于 2024-11-09 13:10:57 字数 2584 浏览 1 评论 0原文

我正在尝试重定向登录到其个人资料页面的用户,但出现以下错误。

No route matches {:action=>"create", :controller=>"trooper_profiles"}

这是我正在遵循的指南。 https: //github.com/plataformatec/devise/wiki/How-to:-redirect-to-a-specific-page-on-successful-sign-in

在我的 application_controller 中,我添加了

def after_sign_in_path_for(resource)
  trooper_trooper_profile_path
end

Rake 路由显示:

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"=>"[email protected]", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Sign in"}
Trooper Load (0.6ms)  SELECT "troopers".* FROM "troopers" WHERE ("troopers"."email" = '[email protected]') 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'

知道为什么路线不匹配吗?

I'm trying to redirect users that login to their profile page but get the following error.

No route matches {:action=>"create", :controller=>"trooper_profiles"}

Here's the guide I'm following.
https://github.com/plataformatec/devise/wiki/How-to:-redirect-to-a-specific-page-on-successful-sign-in

In my application_controller I've added

def after_sign_in_path_for(resource)
  trooper_trooper_profile_path
end

Rake routes shows:

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"}

Server log

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"=>"[email protected]", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Sign in"}
Trooper Load (0.6ms)  SELECT "troopers".* FROM "troopers" WHERE ("troopers"."email" = '[email protected]') 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'

Any idea on why the route doesn't match?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

过气美图社 2024-11-16 13:10:57

您没有告诉您的路径助手要显示哪个士兵个人资料。

尝试更改您的 after_sign_in_path_for 方法:

def after_sign_in_path_for(resource)
  trooper_trooper_profile_path(resource) # Note presence of 'resource'
end

You're not telling your path helper which trooper profile to display.

Try changing your after_sign_in_path_for method thus:

def after_sign_in_path_for(resource)
  trooper_trooper_profile_path(resource) # Note presence of 'resource'
end
抚你发端 2024-11-16 13:10:57

您正在重定向到操作后

you are redirecting to post action

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文