Last active
July 24, 2018 21:57
-
-
Save courtsimas/b6a64b1ad509bb783ef19cf96839e714 to your computer and use it in GitHub Desktop.
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
def grouped_options_from_enum(model, enum, label) | |
grouped_options = [].tap do |opts| | |
model.send(enum.to_s.pluralize).keys.each do |enum_value| | |
opts << [enum_value.humanize, model.send(enum_value).collect {|obj| [obj.send(label), obj.id]}] | |
end | |
end | |
grouped_options | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This probably isn't even safe, but I needed this abstracted because it's used in several places for different models and enums.