2

我有一个文章模型和一个类别模型。类别充当树。

建立一个选择列表以允许管理员从选择列表中选择一个类别以便稍后将其与文章相关联的最佳方法是什么?

semantic_form_for(@article) do |f|
  f.input :title, :as => :string
  f.input :content, :as => :text
  f.input :category, :collection => #what should go here ?
end
4

1 回答 1

0

尝试这个:

f.input :category, :as => :select, :collection => Category.all

或者,您可以将它们指定为(来自文档):

f.input :category,  :as => :select, :collection => { @cat1.name => @cat1id, @cat2.name => @cat2.id }
f.input :category,  :as => :select, :collection => ["cat1", "cat2", "cat3", "cat4", "cat5"]
于 2010-06-11T19:36:24.240 回答