module Virtuaservices::Concerns::Sluggable::ClassMethods
Module holding the class methods for the classes including this concern. @author Vincent Courtois <courtois.vincent@outlook.com>
Public Instance Methods
make_sluggable(entity_type)
click to toggle source
Add the field and its validations in the model including it. @param entity_type [String,Symbol] the name of the model including it, to be included in the error messages.
# File lib/virtuaservices/concerns/sluggable.rb, line 13 def make_sluggable(entity_type) # @!attribute [rw] slug # @return [String] the slug of the current entity ; it must be snake-cased, longer than four characters, unique for the entity and given. field :slug, type: String validates :slug, length: {minimum: 4, message: 'minlength', if: :slug?}, format: {with: /\A[a-z]+(_[a-z]+)*\z/, message: 'pattern', if: :slug?}, uniqueness: {message: 'uniq', if: :slug?}, presence: {message: 'required'} end