# Session destroy link won't work

**URL:** <https://www.ruby-forum.com/t/session-destroy-link-wont-work/150218>\
**Category:** Rails\
**Created:** [October 6, 2008, 6:25am UTC](https://www.ruby-forum.com/t/session-destroy-link-wont-work/150218 "2008-10-06T06:25:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![JHuizingh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8797f3/32.png) [@JHuizingh](https://www.ruby-forum.com/u/JHuizingh)\
**Post date:** [October 6, 2008, 6:25am UTC](https://www.ruby-forum.com/t/session-destroy-link-wont-work/150218/1 "2008-10-06T06:25:45Z")

</div>

I am trying to destroy a session created by Restful authentication  
plugin, but everything I’ve tried doesn’t work. I’ve been googling  
for a while but haven’t found anything that will fix this.

These are the relevant lines that I currently have:

config/routes.rb:

map.resource :session, :member =\> {:logoff =\> :delete }

app/views/layouts/credentials.html.erb:

\<%= link\_to “logout”, logoff\_session\_url %\>

Session Routes from ‘rake routes’:

```
                     POST /session

```

{:controller=\>“sessions”, :action=\>“create”}  
POST /session.:format  
{:controller=\>“sessions”, :action=\>“create”}  
new\_session GET /session/new  
{:controller=\>“sessions”, :action=\>“new”}  
formatted\_new\_session GET /session/new.:format  
{:controller=\>“sessions”, :action=\>“new”}  
edit\_session GET /session/edit  
{:controller=\>“sessions”, :action=\>“edit”}  
formatted\_edit\_session GET /session/edit.:format  
{:controller=\>“sessions”, :action=\>“edit”}  
logoff\_session DELETE /session/logoff  
{:controller=\>“sessions”, :action=\>“logoff”}  
formatted\_logoff\_session DELETE /session/logoff.:format  
{:controller=\>“sessions”, :action=\>“logoff”}  
session GET /session  
{:controller=\>“sessions”, :action=\>“show”}  
formatted\_session GET /session.:format  
{:controller=\>“sessions”, :action=\>“show”}  
PUT /session  
{:controller=\>“sessions”, :action=\>“update”}  
PUT /session.:format  
{:controller=\>“sessions”, :action=\>“update”}  
DELETE /session  
{:controller=\>“sessions”, :action=\>“destroy”}  
DELETE /session.:format  
{:controller=\>“sessions”, :action=\>“destroy”}

And the layout generates the following html:

[logout](http://localhost:3000/session/logoff)

When I click on the logoff link, here is the error that shows up on  
the resulting page:

ActionController::MethodNotAllowed  
Only delete requests are allowed.

I know that the url has to somehow signify that the delete method is  
to be used since web browsers don’t support the delete method, but I’m  
not sure what I’m doing wrong. Can anybody help?

Thanks,  
Jonathan

---

<div class="post-metadata">

**Author:** ![JHuizingh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8797f3/32.png) [@JHuizingh](https://www.ruby-forum.com/u/JHuizingh)\
**Post date:** [October 6, 2008, 9:46am UTC](https://www.ruby-forum.com/t/session-destroy-link-wont-work/150218/2 "2008-10-06T09:46:02Z")

</div>

On Oct 6, 5:25 am, JHuizingh [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> And the layout generates the following html:
> 
> [logout](http://localhost:3000/session/logoff)
> 
> When I click on the logoff link, here is the error that shows up on  
> the resulting page:
> 
> ActionController::MethodNotAllowed  
> Only delete requests are allowed.

Well you’ve sort of figured it out yourself - Your routing demands a  
DELETE method, but your link is a plain old GET.  
Either you change your routing to accept GET requests or you use  
the :method option to link\_to to fake up a DELETE request (watch out,  
this relies on javascript)

Fred

---

<div class="post-metadata">

**Author:** ![JHuizingh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8797f3/32.png) [@JHuizingh](https://www.ruby-forum.com/u/JHuizingh)\
**Post date:** [October 6, 2008, 7:10pm UTC](https://www.ruby-forum.com/t/session-destroy-link-wont-work/150218/3 "2008-10-06T19:10:20Z")

</div>

Thank you. That was it. I could have sworn that I tried that, but I  
guess something else must have been wrong when I tried it. It works  
now. Thanks.

Jonathan

On Oct 6, 1:45 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
