2010-06-11 5 views
2

J'ai un modèle d'article et un modèle de catégorie. La catégorie agit comme un arbre. Quelle est la meilleure approche pour construire une liste de sélection pour permettre à l'administrateur de sélectionner une catégorie dans une liste de sélection pour l'associer plus tard à un article?Formtastic + catégories imbriquées

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 
+0

8 ans plus tard, vous avez jamais comprendre cela? : p – Tashows

Répondre

0

Essayez ceci:

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

Sinon, vous pouvez les spécifier comme cela (à partir de la documentation):

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