Class: Pressroom::Tag
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Pressroom::Tag
- Defined in:
- app/models/pressroom/tag.rb
Constant Summary
Constants included from Sluggable
Constants included from Scoped
Scoped::NO_SCOPE_ID, Scoped::NO_SCOPE_TYPE
Class Method Summary collapse
-
.for_names(names) ⇒ Object
Finds or creates one tag per distinct non-blank name.
Methods included from Scoped
id_for, #scope, #scope=, #scoped?, type_for
Class Method Details
.for_names(names) ⇒ Object
Finds or creates one tag per distinct non-blank name.
17 18 19 20 21 22 23 |
# File 'app/models/pressroom/tag.rb', line 17 def self.for_names(names) Array(names) .map { |name| name.to_s.strip } .reject(&:empty?) .uniq .map { |name| in_scope(default_scope_owner).find_or_create_by!(slug: slugify(name)) { |tag| tag.name = name } } end |