Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Forum
- include Mongoid::Document
- include Mongoid::Timestamps
- include ActionView::Helpers::DateHelper
- field :name, :type => String
- field :description, :type => String
- field :active, type: Boolean, default: true
- field :last_post, :type => Time, default: Time.now
- field :slug, :type => String
- index :slug, :unique => true
- references_many :topics, :foreign_key => :topic_id, :class_name => 'Topic'
- before_create :set_slug
- scope :active, where(:active => true)
- validates_length_of :name, :maximum => 32
- validates_length_of :description, :maximum => 128
- def set_slug
- self.slug = self.name.downcase.gsub(/[^a-z0-9]/,"-")
- end
- def to_param
- self.slug
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement