Sha256: 8e0445a39ea499903f619fef6c878a2df9a3ff97c6325803479155ebfb3b4758
Contents?: true
Size: 546 Bytes
Versions: 27
Compression:
Stored size: 546 Bytes
Contents
require 'cgi' class Slug include Mongoid::Document field :_id, :type => String field :document_id, type: Moped::BSON::ObjectId #validations validate :document_id_should_exist def document_id_should_exist if !Base.where(_id: document_id).exists? errors.add :document_id, "id doesn't exist" end end def generate_id i = 0 i+=1 while Slug.where(_id: i.to_s).exists? self.id = i.to_s end def set_id(url) Slug.delete_all(_id: url) self._id = url.gsub(/[^a-zA-Z0-9\-\/]+/, '-').downcase end end
Version data entries
27 entries across 27 versions & 1 rubygems