我正在尝试使用结合隐藏字段的按钮来更新对象。但是下面的代码将对象更新为“不知道”(结果 [4])。我究竟做错了什么?
<%= form_for(@ask) do |f| %>
<% outcomes = [ "Advice", "Introduction", "Support", "Money", "Don't know" ] %>
<ul>
<% outcomes.each do |o| %>
<li>
<%= f.hidden_field :category, value: o %>
<%= f.submit o, class: "btn btn-success" %>
</li>
<% end %>
</ul>
<% end %>
每个按钮的 HTML 是:
<input id="ask_category" name="ask[category]" type="hidden" value="Introduction" /> #value is equal to each object in the array
<input class="btn btn-success" name="commit" type="submit" value="Introduction" />
这看起来也不错...