如何为模型生成一个选择字段?如何将选择(下拉列表)添加到我生成的表单中?
我的控制器发送应该用来填充选择的数组。
控制器:
def new
@categories= Category.all
@product= Product.new
end
类型模型有一个ID和一个标签。
的形式如下:
=form_for :product do |f|
- if @product.errors.any?
#error_explanation
%h2
= pluralize(@product.errors.count, "error")
prohibited
this product from being saved:
%ul
- @product.errors.full_messages.each do |msg|
%li= msg
%p
= f.label :title
%br
= f.text_field :title
%p
= f.label :category_id
%br
= f.xxxxxxxxx
%p
= f.submit
xxxxxxxxx
是我需要选择由@categories
数组填充的地方。
谢谢,现在我明白了。它工作得很好。 – LogofaT