Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 0.73 KB | None | 0 0
  1. class Forum
  2.   include Mongoid::Document
  3.   include Mongoid::Timestamps
  4.   include ActionView::Helpers::DateHelper
  5.  
  6.   field :name, :type => String
  7.   field :description, :type => String
  8.   field :active, type: Boolean, default: true
  9.   field :last_post, :type => Time, default: Time.now
  10.   field :slug, :type => String
  11.  
  12.   index :slug, :unique => true
  13.  
  14.   references_many :topics, :foreign_key => :topic_id, :class_name => 'Topic'
  15.  
  16.   before_create :set_slug
  17.  
  18.   scope :active, where(:active => true)
  19.  
  20.   validates_length_of :name, :maximum => 32
  21.   validates_length_of :description, :maximum => 128
  22.  
  23.   def set_slug
  24.     self.slug = self.name.downcase.gsub(/[^a-z0-9]/,"-")
  25.   end
  26.  
  27.   def to_param
  28.     self.slug
  29.   end
  30.  
  31. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement