rubyruby-on-rails-4sorcery

Sorcery Log_out not working


Here is my route-

    get 'login' => 'sessions#new'
    post 'login' => 'sessions#create'
    delete 'logout' => 'sessions#destroy'

Here is my controller action-

  def destroy
    logout
    redirect_to(login_url, notice: 'You have Succesfully Logged out.')
  end

Here is my view-

  <li>
      <%if current_user %>
      <%= link_to logout_path, method: :delete do %>
      <i class="fa fa-sign-out"></i> Log out
      <%end%>
      <%end%>
  </li>

The problem I am having is: whenever I logout it says-

No route matches [GET] "/logout".

I tried with GET, I tried with DELETE and POST, nothing works.

Routes

login_path  GET     /login(.:format)    sessions#new
            POST    /login(.:format)    sessions#create
logout_path DELETE  /logout(.:format)   sessions#destroy

Solution

  • Make sure you have these in your app/assets/javascripts/application.js

    //= require jquery
    //= require jquery_ujs