Magic 'show' action

A

Alex Birkett

I can't understand why my action, 'login' is being redirected to 'show'
with login passed as an 'id'.

So when I go to to the url http://localhost:3000/users/login

Development.log shows:
Processing UsersController#show (for 127.0.0.1 at 2008-06-19 12:45:04)
[GET]
Session ID: xxxxxxxxxxxxxxxxxxxxxxxxxxxx
Parameters: {"action"=>"show", "id"=>"login", "controller"=>"users"}

When I got to the url: http://localhost:3000/users/login/1

Development.log shows:
Processing UsersController#login (for 127.0.0.1 at 2008-06-19 12:42:20)
[GET]
Session ID: xxxxxxxxxxxxxxxxxxxxxxxxxxxx
Parameters: {"action"=>"login", "id"=>"1", "controller"=>"users"}

and the login page loads.

I've grepped the whole project and I can't find reference to the 'show'
action anywhere.

My controller is attached.

Any help appreciated.

Thanks,

Alex

Attachments:
http://www.ruby-forum.com/attachment/2226/users_controller.rb
 
E

Eleanor McHugh

I can't understand why my action, 'login' is being redirected to
'show'
with login passed as an 'id'.

So when I go to to the url http://localhost:3000/users/login

Development.log shows:
Processing UsersController#show (for 127.0.0.1 at 2008-06-19 12:45:04)
[GET]
Session ID: xxxxxxxxxxxxxxxxxxxxxxxxxxxx
Parameters: {"action"=>"show", "id"=>"login", "controller"=>"users"}

When I got to the url: http://localhost:3000/users/login/1

Development.log shows:
Processing UsersController#login (for 127.0.0.1 at 2008-06-19
12:42:20)
[GET]
Session ID: xxxxxxxxxxxxxxxxxxxxxxxxxxxx
Parameters: {"action"=>"login", "id"=>"1", "controller"=>"users"}

and the login page loads.

I've grepped the whole project and I can't find reference to the
'show'
action anywhere.

My controller is attached.

You'll probably get a more useful answer from the rails mailing list,
but at a rough guess I'd suggest that you read your routes.rb file and
add a named route for your login controller.


Ellie

Eleanor McHugh
Games With Brains
http://slides.games-with-brains.net
 
A

Alex Birkett

Eleanor said:
You'll probably get a more useful answer from the rails mailing list,
but at a rough guess I'd suggest that you read your routes.rb file and
add a named route for your login controller.

Hi Eleanor,

Thanks for you response, I'll have to subscribe to the list.

I've fixed the problem by commenting out this line in routes.rb:
map.resources :users

I still don't understand where the action named 'show' comes from
though.

Alex
 
E

Eleanor McHugh

I've fixed the problem by commenting out this line in routes.rb:
map.resources :users

I still don't understand where the action named 'show' comes from
though.

I'm not a Rails expert so I'm sure someone will step in and correct
the following ;p

When you use map.resource Rails creates a set of RESTful routes for
the resource in question, so when you hit the URL /users/login/ it's
treating login as the parameter to pass to the show method of the
UsersController controller as opposed to looking for the
Users::LoginController that you intend.

A simple solution would be to define a named route for /users/login/
prior to map.resource :users as the named route would take precedence,
however if you're looking to make your application RESTful a better
choice of URL scheme might be /session/[create|show|list|etc.] and
treat the session itself as a RESTful entity.

Hopefully that's intelligible :)


Ellie

Eleanor McHugh
Games With Brains
http://slides.games-with-brains.net
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,666
Latest member
selsetu

Latest Threads

Top