我有一个按钮:
<%= button_to "Unsubscribe", cancel_subscription_path, method: :post, data: { confirm: "Are you sure?" } %>
我正在尝试为此按钮添加样式。
我试过
<%= button_to "Unsubscribe", cancel_subscription_path, method: :post, data: { confirm: "Are you sure?" }, {class:"myClass"} %>
和
<%= button_to "Unsubscribe", {cancel_subscription_path, method: :post, data: { confirm: "Are you sure?" }}, {class:"myClass"} %>
答案 0 :(得分:2)
我认为这对你有用
<%= button_to "Unsubscribe", root_path, method: :post, data: { confirm: "Are you sure?" }, class:"myClass" %>
它会生成这样的表格
<form class="button_to" method="post" action="/">
<input data-confirm="Are you sure?" class="myClass" type="submit" value="Unsubscribe">
<input type="hidden" name="authenticity_token" value="ViECdS4KxrTfhazHRcx/6uUp+VXYUUUrqIMNX7jCz24cpeIEcY41IGDAHU1KLOYp2RuwNidxyIKHRlZubUU61SLA==">
</form>
有关详细信息,请查看示例部分here。
答案 1 :(得分:1)
您可以尝试以下
<%= button_tag class: "myClass", method: :post,url: cancel_subscription_path, data: { confirm: "Are you sure?" } do %>
Unsubscribe
<% end %>
或者,如果您使用表格,则使用以下内容
<%= form_tag cancel_subscription_path, method: :post do %>
<%= button_tag class: "myClass", type: "submit", data: { confirm: "Are you sure?" } do %>
Unsubscribe
<% end %>
<% end %>
希望能提供帮助
答案 2 :(得分:0)
您可以尝试:
<%= button_to "Unsubscribe", root_path, method: :post, data: { confirm: "Are you sure?" }, class: "btn-lg btn-danger delete-btn" %>
这也有效:
<%= button_to "Unsubscribe", root_path, method: :post, data: { confirm: "Are you sure?" }, :class => "btn-lg btn-danger delete-btn" %>