多个字段不以单一形式和模型Rails显示

时间:2014-05-02 17:33:48

标签: ruby-on-rails

我有模特产品。我想在单个模型(产品)中创建多个记录,但字段不在视图中显示

#controller

@products = Array.new(3){ Product.new }

# view

<%= form_tag create_product_path, :method => :post, :class => "form-horizontal",  'role' => "form" do %>
<% @products.each_with_index do |product, index| %>
 <% fields_for "products[#{index}]", product do |f| %>
   <%= f.text_field :date  %>
   <%= f.text_field :name  %>
 <% end %>
<% end %>
<%= submit_tag "Submit", :class => "btn btn-primer" %>
   

查看此屏幕截图,不显示字段。任何人都可以告诉我,为什么没有出现使用数组的新表单方法?

notdisplay

1 个答案:

答案 0 :(得分:1)

不要忘记<%=

上的fields_for

阅读fields_for

rails 2.x - 3.0

<% fields_for "products[#{index}]", product do |f| %>

rails&gt; 3.1.X

<%= fields_for "products[#{index}]", product do |f| %>