class Bulletin include Mongoid::Document include Mongoid::Timestamps field :title, type: String, localize: true field :body, type: String, localize: true field :uid, type: String # include Slug def to_param self.title.gsub(/[ "'*@#$%^&()+=;:.,?>|\\<~_!]/,'-').gsub(/-{2,}/,'-')+'-'+self.uid end def self.find_by_param(input) self.find_by(uid: input) end def generate_uid self.uid = rand(36**8).to_s(36) self.save end end