[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Magic 'show' action

Alex Birkett

6/19/2008 11:55:00 AM

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-...attachment/2226/users_con...

--
Posted via http://www.ruby-....

3 Answers

Eleanor McHugh

6/19/2008 1:16:00 PM

0

On 19 Jun 2008, at 12:55, Alex Birkett wrote:
> 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-...
----
raise ArgumentError unless @reality.responds_to? :reason



Alex Birkett

6/19/2008 1:49:00 PM

0

Eleanor McHugh wrote:
> On 19 Jun 2008, at 12:55, Alex Birkett wrote:
>> Parameters: {"action"=>"show", "id"=>"login", "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.
>

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
--
Posted via http://www.ruby-....

Eleanor McHugh

6/19/2008 3:00:00 PM

0

On 19 Jun 2008, at 14:49, Alex Birkett wrote:
> 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-...
----
raise ArgumentError unless @reality.responds_to? :reason