How can I get the class name of a model I am including a concern into?
I am creating a concern for a scope as described in here https://stackoverflow.com/a/14483808/1715035 but need the model name for polymorphic search.
self.table_name
works fine and so does self.table_name.singularize.titleize.gsub(/\s+/, "")
but maybe theres an easier way to get the class name.
You can use the name
method as you would in the class itself.
module M
extend ActiveSupport::Concern
included do
scope :my_fancy_scope, where(some_type: name)
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With