To define my ajax functions, I normally use a <%= link_to %> to add a remote:true method. But I have a tag line
<a href="/posts/<%= post.id %>/undone" data-method="patch"><i class="fa fa-close" aria-hidden="true" style="margin-right: 10px;"></i>Cancel</a>
that I want to run with ajax.
And I cannot change it into a link_to because it's crashing all my design. So do you know a method to achieve that ?
答案 0 :(得分:2)
remote: true
只是添加属性data-remote="true"
的快捷方式。将此添加到您的锚标记,它应该具有相同的效果。 E.g。
<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 %>