I am using the restful_authentication plugin. This creates the users
controller which is declared as a resource in routes.rb as below
map.resources :users
Now in the UsersController I have created an action to resetpwd that I
am trying to get to from the login page when the user clicks “forgot
password”. However, when I do that the log file tells me that the call
to /users/resetpwd gets resolved to the “show” action of the controller
with id=“resetpwd” as below
Processing UsersController#show (for 127.0.0.1 at 2009-04-30 21:05:13)
[GET]
Parameters: {“id”=>“resetpwd”}
SQL (0.0ms) SET NAMES ‘utf8’
SQL (0.0ms) SET SQL_AUTO_IS_NULL=0
In the script/console when I list all the routes, here is a subset of
what I get
GET /users/:id/ {:controller=>“users”, :action=>“show”}
GET /users/:id.:format/ {:controller=>“users”, :action=>“show”}
That may explain why /users/resetpwd is mapping to the show action in
UsersController because “resetpwd” is being taken as the :id for the GET
action on /users. But when I run a recognize_path command as below in
script/console it seems to resolve correctly
Then Rails would map ‘/users/resetpwd’ to resetpwd_users_url
Chris
Sj Tib wrote:
Folks,
I am using the restful_authentication plugin. This creates the users
controller which is declared as a resource in routes.rb as below
map.resources :users
Now in the UsersController I have created an action to resetpwd that I
am trying to get to from the login page when the user clicks “forgot
password”. However, when I do that the log file tells me that the call
to /users/resetpwd gets resolved to the “show” action of the controller
with id=“resetpwd” as below
Processing UsersController#show (for 127.0.0.1 at 2009-04-30 21:05:13)
[GET]
Parameters: {“id”=>“resetpwd”}
SQL (0.0ms) SET NAMES ‘utf8’
SQL (0.0ms) SET SQL_AUTO_IS_NULL=0
In the script/console when I list all the routes, here is a subset of
what I get
GET /users/:id/ {:controller=>“users”, :action=>“show”}
GET /users/:id.:format/ {:controller=>“users”, :action=>“show”}
That may explain why /users/resetpwd is mapping to the show action in
UsersController because “resetpwd” is being taken as the :id for the GET
action on /users. But when I run a recognize_path command as below in
script/console it seems to resolve correctly
When I print out the possible routes in script/console I get the
following (relevant subset)
GET /users/resetpwd/ {:controller=>“users”,
:action=>“resetpwd”}
GET /users/resetpwd.:format/ {:controller=>“users”,
:action=>“resetpwd”}
GET /users/:id/ {:controller=>“users”,
:action=>“show”}
GET /users/:id.:format/ {:controller=>“users”,
:action=>“show”}
Clearly /users/resetpwd should now route to :controller=>“users”,
:action=>“resetpwd”
However when I go to my localhost/users/resetpwd I get a Routing error
saying
No route matches “/” with {:method=>:get}
In my dev log file I see the following
Processing UsersController#resetpwd (for 127.0.0.1 at 2009-05-01
09:45:40) [GET]
SQL (0.0ms) SET NAMES ‘utf8’
SQL (0.0ms) SET SQL_AUTO_IS_NULL=0
Redirected to /
Completed in 0ms (DB: 0) | 302 Found [http://localhost/users/resetpwd]
Processing ApplicationController#index (for 127.0.0.1 at 2009-05-01
09:45:41) [GET]
ActionController::RoutingError (No route matches “/” with
{:method=>:get}):
I notice a 302 response code which is redirecting the request. I don’t
understand why this is getting sent to ApplicationController. I had a
map.root statement in my routes.rb that I have temporarily commented out
to debug this problem which would address this routing error. But I
don’t understand why I can’t get to /users/resetpwd and instead get
redirected.
Thanks Colin. I looked into it more and found a bug. I can get to the
resetpwd action in the Users controller now. Chris’s routing change
suggestion resolved the issue.