使用button_tag或form_for

时间:2015-06-18 00:42:48

标签: ruby-on-rails twitter-bootstrap

在表单提交按钮中使用bootstrap glyphicon看似微不足道的任务就是。我无法让button_tagform_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?

1 个答案:

答案 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}}