Forum: Ruby on Rails Session destroy link won't work

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
7e810c122918c5afe00f3b4f963b6968?d=identicon&s=25 JHuizingh (Guest)
on 2008-10-06 06:25
(Received via mailing list)
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:

  <a href="http://localhost:3000/session/logoff">logout</a>...

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
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2008-10-06 09:46
(Received via mailing list)
On Oct 6, 5:25 am, JHuizingh <JHuizi...@gmail.com> wrote:

> And the layout generates the following html:
>
>   <a href="http://localhost:3000/session/logoff">logout</a>...
>
> 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
7e810c122918c5afe00f3b4f963b6968?d=identicon&s=25 JHuizingh (Guest)
on 2008-10-06 19:10
(Received via mailing list)
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 Cheung <frederick.che...@gmail.com>
This topic is locked and can not be replied to.