【问题标题】:Remote true for a <a><a> 的远程 true
【发布时间】:2017-06-07 22:14:56
【问题描述】:

为了定义我的 ajax 函数,我通常使用 添加一个 remote:true 方法。但我有一个标语行

<a href="/posts/<%= post.id %>/undone" data-method="patch"><i class="fa fa-close" aria-hidden="true" style="margin-right: 10px;"></i>Cancel</a>

我想用 ajax 运行。

而且我无法将其更改为 link_to,因为它破坏了我的所有设计。 那么你知道实现这一目标的方法吗?

【问题讨论】:

  • &lt;a href="/posts/&lt;%= post.id %&gt;/undone" data-method="patch"&gt;&lt;i class="fa fa-close" aria-hidden="true" style="margin-right: 10px;" data-remote="true"&gt;&lt;/i&gt;Cancel&lt;/a&gt; 试试这个
  • 为什么不能使用link_to?它需要一个可以轻松设置所有样式的块stackoverflow.com/questions/24461903/…
  • 谢谢你们的回答! @Iceman,因为当您使用引导下拉菜单时,您必须使用 标签而不是链接到。如果不是,则样式不起作用
  • @stigGaret:“你必须使用&lt;a&gt; 而不是link_to”——这不可能。 link_to 所做的是生成&lt;a&gt; 标签。
  • 好吧,伙计们,我都知道,但是尝试在引导下拉菜单中实现一个 link_to,你会看到链接的样式正在发生变化

标签: ruby-on-rails


【解决方案1】:

remote: true 只是添加属性data-remote="true" 的快捷方式。将此添加到您的锚标记中,它应该具有相同的效果。例如

<a href="/posts/<%= post.id %>/undone" data-method="patch" data-remote="true">

也就是说 - 是什么阻止您使用 link_to?您可以将它与块一起使用,例如:

<%= link_to undone_posts_path(post.id), remote: true, method: :patch do %>
  <i class="fa fa-close" aria-hidden="true" style="margin-right: 10px;"></i>
  Cancel
<% end %>

【讨论】:

  • 谢谢@gwcodes,这正是我要找的
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-28
  • 2023-03-30
  • 2013-01-07
  • 1970-01-01
相关资源
最近更新 更多