0

I am having some strange errors since I implemented bootstrap into my project. Currently I can not log out because a DESTROY request is being replaced by a GET request. This exact same link worked fine until I made my menu bootstrap. Here is the link:

<li><a href="<%= session_path(current_user.id)%>">Logout</a></li>

here is what is in the session controller:

    def destroy
        log_out
        redirect_to root_path
    end

here is what my routes look like: enter image description here

What is the best way to fix this? Adding method: :delete to the link did not work. Thanks!

UPDATE:

here is my bundle exec rake routes | grep session: enter image description here

and here is my routes.rb:

Rails.application.routes.draw do
 root to: 'application#home'
 resources :users
 resources :sessions, only: [:new, :create, :destroy] 
end
HolyMoly
  • 2,020
  • 3
  • 22
  • 35
  • I don't think Bootstrap could influence that in any way. What other changes did you apply since the error appeared? – aledalgrande Aug 22 '15 at 22:10
  • you should provide the relevant results of `rake routes` and/or some of your `config/routes.rb` file. – xlembouras Aug 22 '15 at 22:13
  • post the `rake routes` output please – K M Rakibul Islam Aug 22 '15 at 22:14
  • ok i will upload my routes in the question – HolyMoly Aug 22 '15 at 22:14
  • @aledalgrande I wouldn't think so either, I am verrry new to bootstrap, but my google search of this revealed another person with the same error, who upon removing the bootstrap (he just said 'cleaning up my css' actually) found the error resolved once he did that. And as I mentioned, this exact link worked prior to putting it in bootstrap, so while I could be, and hope, I am wrong about bootstrap being the cause, it seems it very well may be - as I havent really done anything since it WAS working, except add boot strap – HolyMoly Aug 22 '15 at 22:22

1 Answers1

2

Destructive actions should be performed as a form submission - http://www.w3.org/2001/tag/doc/whenToUseGet.html#checklist

<%= button_to "delete", session_path(current_user.id), :method=>:delete, :class=>:destroy %>

Also, add your

  <%= csrf_meta_tags %>

To your layout in case you have not. I do not know how bootstrap might be an issue, but tags certainly are. They can make the difference between a DELETE and a GET request from a route.

Hristo Georgiev
  • 2,499
  • 1
  • 16
  • 23
  • do I just add that to the head of my application.html.erb file? – HolyMoly Aug 22 '15 at 22:47
  • this works!! But is there a way to not use a button? this is part of a drop down menu,` My Account > My Profile > Logout` and i would really like to keep it like this....I have tried using your code inside a `link_to` and it won't work, is there a way to get the same result without a button? either way this is a leap in the right direction and I appreciate it! also, why do you think this worked previously, as is, until I added bootstrap? I would love to get to the bottom of this – HolyMoly Aug 22 '15 at 22:52
  • I think it should work, let me check one of my projects where I encountered this problem – Hristo Georgiev Aug 22 '15 at 22:53
  • awesome that would be great! – HolyMoly Aug 22 '15 at 22:54
  • <%= link_to 'destroy', session_path(current_user.id), :method => :delete %> is what I had in a previous project. If this does not work, then I'm afraid you'll have to attempt to remove all the styling from the button to make it look like a link. – Hristo Georgiev Aug 22 '15 at 22:59