开发者

Formtastic + nested categories

I have an article model and an category model. Category act as tree.

What is the best approch to build a select list to allow the adm开发者_如何转开发inistrator to select an category from a select list to associate it later with an article ?

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


Try this:

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

Alternatively you could specify them as this (from the docs):

f.input :category,  :as => :select, :collection => { @cat1.name => @cat1id, @cat2.name => @cat2.id }
f.input :category,  :as => :select, :collection => ["cat1", "cat2", "cat3", "cat4", "cat5"]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜