views:

37

answers:

1

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 administrator 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
A: 

Hi there,

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"]
cristian