在表单提交按钮中使用bootstrap glyphicon看似微不足道的任务就是。我无法让button_tag
或form_for
工作。
button_tag
成功显示了glyphicon,但失败了,因为(查看控制台)它没有向服务器提交请求。它已经死了,没有任何反应:
<%= button_tag(type: 'submit', name: nil, class: 'btn btn-default btn-xs', id: 'vote_button',
path: postvoterelationships_path, remote: true) do %>
<span class='glyphicon glyphicon-star-empty' aria-hidden="true"></span>
<%= hidden_field_tag(:voter_callsign, @character.callsign) %>
<%= hidden_field_tag(:voted_id, @post.id) %>
<% end %>
form_for
失败了,因为在成功发送请求的同时,我无法显示该字形。以下两个版本都只是创建了一个大的灰色按钮,其中包含创建Postvoterelationshiop&#39;在中间:
<%= form_for(@character.active_post_vote_relationships.build, remote: true) do |f| %>
<div><%= hidden_field_tag(:voter_callsign, @character.callsign) %></div>
<div><%= hidden_field_tag(:voted_id, @post.id) %></div>
<%= f.submit do %>
<span class="glyphicon glyphicon-star-empty"></span>
<% end %>
<% end %>
<%= form_for(@character.active_post_vote_relationships.build, remote: true) do |f| %>
<div><%= hidden_field_tag(:voter_callsign, @character.callsign) %></div>
<div><%= hidden_field_tag(:voted_id, @post.id) %></div>
<%= f.submit class: "glyphicon glyphicon-star-empty" %>
<% end %>
如何让button_tag
提交请求,或form_for
显示glyphicon?
答案 0 :(得分:0)
您可以尝试<%= button_to postvoterelationships_path, class: 'btn btn-default btn-xs', params: {voter_callsign: @character.callsign, voted_id: @post.id}, remote: true do %>
<span class="glyphicon glyphicon-star-empty"></span>
<% end %>
{{1}}