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