Ruby on rails 在路径中设计后符号以产生路由错误

Ruby on rails 在路径中设计后符号以产生路由错误,ruby-on-rails,ruby-on-rails-3,devise,Ruby On Rails,Ruby On Rails 3,Devise,我正在尝试将登录到其配置文件页面的用户重定向,但出现以下错误 No route matches {:action=>"create", :controller=>"trooper_profiles"} 这是我遵循的指南。 在我的应用程序中,我添加了 def after_sign_in_path_for(resource) trooper_trooper_profile_path end Rake routes显示: trooper_trooper_profile POST

我正在尝试将登录到其配置文件页面的用户重定向,但出现以下错误

No route matches {:action=>"create", :controller=>"trooper_profiles"}
这是我遵循的指南。

在我的应用程序中,我添加了

def after_sign_in_path_for(resource)
  trooper_trooper_profile_path
end
Rake routes显示:

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'

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

你没有告诉你的路径助手要显示哪一个骑兵档案

尝试在方法的路径中签名后更改您的:

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

您正在重定向到post action

不确定这是否只是我,但我必须将其放在application_helper.rb中,而不是application_controller.rb中。文档建议放入控制器,但在对路径进行签名之后,实际上是一个助手,而不是控制器方法。