Last active
February 4, 2023 13:24
-
-
Save EtienneDepaulis/6988148 to your computer and use it in GitHub Desktop.
Generating a grouped collection select with `simple_form`and a model using the `ancestry` gem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= | |
f.association :category_id, collection: Category.roots, | |
as: :grouped_select, | |
group_method: :children, group_label_method: :name, | |
label_method: :name | |
%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Category < ActiveRecord::Base | |
attr_accessible :name | |
has_ancestry orphan_strategy: :adopt | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment