Files
growstuff/app/models/role.rb
2018-01-03 17:16:14 +13:00

16 lines
405 B
Ruby

class Role < ApplicationRecord
extend FriendlyId
friendly_id :name, use: %i(slugged finders)
has_and_belongs_to_many :members # rubocop:disable Rails/HasAndBelongsToMany
class << self
%i(crop_wranglers admins).each do |method|
define_method method do
slug = method.to_s.singularize.dasherize
Role.where(slug: slug).try(:first).try(:members)
end
end
end
end