10 Nov
Options raggruppate per le Select
Come sicuramente sapete è possibile raggruppare le option di una select, per fare questo il Rails vi viene in aiuto con questo Helper option_groups_from_collection_for_select. Io ho avuto un attimo di esitazione per passare i parametri corretti ecco il perchè del post.
1 option_groups_from_collection_for_select(Category.find(:all), 2 "children.find(:all)", 3 "name", 4 "id", 5 "name")
Category è la tabella con le categorie che si comporta, ad esempio, come Acts_as_tree, ecco perchè il parametro successivo dell’option_groups_from_collection_for_select è ciò che deve essere fatto su categories per riempire le option di ogni singolo raggruppamento.
Non è niente di importante ma spero lo troviate comunque utile.


Thank you for this elegant solution with children.find!
K.
Thank you!
thank you.
thank you.
Thank you! =)
Thank you for your solution. But I’m asking how to do if there are no children. So I tried like you with Category model where there are parents and their children. But some times I have only a parent without any children. In this case I have a ‘double’ showing like that:
-subcategory1 (shown as a child)
More of that, I don’t know why I can’t select any of the categories in the list.
Any suggestions?
In fact, I can’t select any parent element, only its children are selectable. Isn’t it possible to select a ‘parent’ no matter if he has children or not.Thank you.
Thanks! it works perfectly!