0

I am working a basic rails miniblog tutorial that is based on an older rails (dunno if that is the problem). I am trying to implement user logout (terminate a user session).

I have this in my form:

<%= link_to 'Logout', session_path(current_user), method: :delete %>

and my rake routes table looks good:

session DELETE /sessions/:id(.:format)         sessions#destroy

but when I test it on local server, by clicking on 'Logout', I was given this error:

No route matches [GET] "/sessions/1"

It really should not have been a [GET] request. I checked that I included all the necessary javascript lines and bundle. What went wrong?

p.s. here is my repo: https://github.com/lukexuanliu/CornellBlog

p.p.s. my problem is very similar to this one: Routing Error No route matches [GET] "/microposts/304 - Deleting a Micropost - Michael Hartl's railstutorial.org Chapter 11

but their solution does not work for me. also, my bootstrap css is kind of messed up... dunno if that contributed to the problem

Community
  • 1
  • 1
  • In your `routes.rb` you have `resources :sessions, only: [:new, :create, :destroy]` but if you're passing the `current_user` to your `session_path` shouldn't your routes be nested: `resources :users do resources :sessions, only: [:new, :create, :destroy] end`? – vich Sep 19 '14 at 01:06
  • session_path(current_user) is translated to /sessions/1 if I have only one user to test with, for reason I do not fully understand. I followed the tutorial and the route table seemed fine. – user3527137 Sep 19 '14 at 02:05
  • Strange. I cloned down your repo and other than tweaking your nav bar a bit so I could see the links, your logout link seems to work. – O-I Sep 19 '14 at 02:39
  • When was the last time you restarted your server? – vich Sep 19 '14 at 04:02

1 Answers1

0

I think I found the problem. When I said "by clicking on Logout," I actually pull out the html code (using inspect element) to click on the actual code "session/1" which will mistakenly issue a [GET] request. as I clean up my stylesheets (turns out to be incompatibility of bootstrap2 code running on bootstrap3 api) and revealed the Logout button to click on, it works fine. curious.