When you’re setting up logins in Rails, the tutorials tell you to store action_name
and controller_name
in the session so you can redirect there later… Capture request.path
instead. This works just fine:
…until you’re using restful resources and a logged-out user clicks an edit link. When Rails tries to take them to “/entries/edit” (controller followed by action) instead of “/entries/1/edit”, it’ll bomb:
ActiveRecord::RecordNotFound in EntriesController#show Couldn't find Entry with ID=edit
So this is better:
Oh, and when they say to put this in your ApplicationController
:
Do this instead:
…and then put this in specific Controllers where you need the exception: