简体   繁体   中英

Devise after_sign_in_path_for generates routing error

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"=>"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'

Any idea on why the route doesn't match?

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

you are redirecting to post action

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM