Skip to content

Instantly share code, notes, and snippets.

@courtsimas
Last active July 24, 2018 21:57
Show Gist options
  • Save courtsimas/b6a64b1ad509bb783ef19cf96839e714 to your computer and use it in GitHub Desktop.
Save courtsimas/b6a64b1ad509bb783ef19cf96839e714 to your computer and use it in GitHub Desktop.
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
@courtsimas
Copy link
Author

This probably isn't even safe, but I needed this abstracted because it's used in several places for different models and enums.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment