announcement-test/app/models/bulletin.rb

23 lines
468 B
Ruby
Raw Normal View History

2014-04-01 07:12:43 +00:00
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
2014-04-02 06:44:36 +00:00
def to_param
self.title.gsub(/[ "'*@#$%^&()+=;:.,?>|\\<~_!]/,'-').gsub(/-{2,}/,'-')+'-'+self.uid
end
2014-04-01 07:12:43 +00:00
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