Elixir phoenix Logout link not working

I have the following exit link in my application, but when I click on it, it does nothing.

<li class="nav-item">
  <%= link "Logout", to: session_path(@conn, :delete), method: :delete, class: "nav-link" %>
</li>

The html element that generates the above code is

<li class="nav-item">
  <form action="/logout" class="link" method="post">
    <input name="_method" type="hidden" value="delete">
    <input name="_csrf_token" type="hidden" value="GiA4JANYN10+JQhfUgIEARxZCRIEAAAUijC25v5Kj8j7KI6qrOtv==">
    <a data-submit="parent" href="#">Logout</a>
  </form>
</li>

Does anyone see something clearly wrong here that the exit link will not do anything when clicked?

brunch-config.js

javascripts: {
 joinTo: {
   "js/app.js": /^(web\/static\/js)/,
   "js/jquery-ujs.js.js": ["web/static/vendor/js/jquery-ujs.js.js"],
   "js/jquery.js": ["web/static/vendor/js/jquery.js"]
 },
 ...
+4
source share
3 answers

I believe that the code responsible for handling such cases is in the js file phoenix_html, so you need to make sure that you add this package to mixand in the line of your app.js file is uncommented:

import "deps/phoenix_html/web/static/js/phoenix_html"

+2
source

A possible workaround is a GET request instead of a DELETE request:

html.eex:

<li class="nav-item">
  <%= link "Logout", to: session_path(@conn, :delete), class: "nav-link" %>
</li>

router.ex:

resources "/sessions", SessionController, only: [:new, :create]
get "/sessions", SessionController, :delete
0

- npm.

phoenix.server , app.js - babel-preset-2015, babel-preset-2016.

npm i --save-dev babel-preset-2015 babel-preset-2016
0
source

Source: https://habr.com/ru/post/1621662/


All Articles