link 错误:删除会话 (PHOENIX)

Error with link to: in deleting a session (PHOENIX)

我有一个link删除当前用户的会话

<%= link "Logout", to: session_path(@conn, :delete, current_user.id), method: :delete, class: "button alert" %>

由于某种原因,它不起作用,尽管当我将 link 更改为按钮时,一切似乎都工作正常。

<%= button "Logout", to: session_path(@conn, :delete, current_user.id), method: :delete, class: "button alert" %>

我很困惑,可能是导致此错误的原因。

有人遇到同样的问题吗?

这只是我的猜测,但根据文档:

:method - the method to use with the link. In case the method is not :get, the link is generated inside the form which sets the proper information. In order to submit the form, JavaScript must be enabled

可能你的项目javascript有问题。

这可以解释为什么按钮实际上起作用了:

Generates a button that uses a regular HTML form to submit to the given URL.