现在我连续有两个表格
<section>
<%= render 'shared/micropost_form_purchase' %>
<%= render 'shared/micropost_form_sale' %>
</section>
然后为 _micropost_form_purchase.html.erb
<%= form_for(@micropost) do |f| %>
<%= render 'shared/error_messages', object: f.object %>
<div class="field no-indent">
<%= f.text_area :content, placeholder: "What's something else you want to buy?" %>
<%= f.hidden_field_tag :type, :value => "purchase" %>
</div>
<%= f.submit "Post", class: "btn btn-large btn-primary" %>
<% end %>
对于 _micropost_form_sale.html.erb 我有
<%= form_for(@micropost, :html => { :id => "sale" }) do |f| %>
<%= render 'shared/error_messages', object: f.object %>
<div class="field no-indent">
<%= f.text_area :content, placeholder: "What's something else you want to buy?" %>
<%= f.hidden_field_tag :type, :value => "sale" %>
</div>
<%= f.submit "Post", class: "btn btn-large btn-primary" %>
<% end %>
所以我希望第一个微博自动成为购买微博(我在微博数据库中有一个名为 type 的列,它是一个我想描述销售或购买的字符串),第二个微博我希望它成为销售微博。我使用 hidden_field_tag 是因为我认为您不必在控制器中定义它,但我错了吗?hidden_field 更合适吗?如何使用 hidden_field_tag?