Bootstrap styled button not being applied to Phoenix delete link

瘦欲@ 提交于 2019-12-24 00:54:49

问题


  • Elixir version: 1.3.2
  • Phoenix version: 1.2.1
  • NodeJS version: 4.4.6
  • NPM version: 3.10.6
  • Brunch version: 2.7.4
  • Operating system: Mac OSX

I am trying to create what suppose to be a simple link using Phoenix's link helper function.

<li><%= link "Logout", to: session_path(@conn, :delete, user), method: :delete %></li>

renders

<form action="/logout/1" class="link" method="post">
  <input name="_method" type="hidden" value="delete">
  <input name="_csrf_token" type="hidden" value="VhxiLApJElIS...removed for clarity">
  <a data-submit="parent" href="#" rel="nofollow">Logout</a>
</form> 

The button works fine and the user logs out but the styling of the button isn't being applied. See below:

The "logout" button should be aligned with and contain hover effects like the "Home" button . What is removing the styling of the logout button?

When a user logs out the styling returns:

Here are other related issues on the delete link functionality.

  • Delete link not working phoenix
  • https://github.com/phoenixframework/phoenix/issues/1204
  • https://github.com/phoenixframework/phoenix/issues/1408
  • https://github.com/phoenixframework/phoenix/issues/1319

Here's what I've tried based on the other issues I've found:

  • run brunch build- compilation succeeds
  • change the link function to button

Hopefully this is enough information to get some input.


回答1:


The delete links do create a form and this is expected. If you look at what the generators create, its something like below:

<%= link "Delete", to: schedule_path(@conn, :delete, schedule), method: :delete, data: [confirm: "Are you sure?"], class: "btn btn-danger btn-xs" %>

You cannot call a delete or post method from a anchor directly, so Phoenix makes a form for you. It's a convenience feature, but can be confusing at first. So if the form is not working the problem may be in your controller not with the form itself.



来源:https://stackoverflow.com/questions/39358259/bootstrap-styled-button-not-being-applied-to-phoenix-delete-link

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!