Sha256: 7880029b36a33412912f6a240337e5bb4cde49e3b250b116f81a31c99e848051
Contents?: true
Size: 761 Bytes
Versions: 1
Compression:
Stored size: 761 Bytes
Contents
class Article < ActiveRecord::Base has_many :comments, dependent: :destroy belongs_to :user validates :title, presence: true validates :text, presence: true validate :vulgarity_level class << self def published; where.not published_at: nil end end def published?; published_at.present? end def publish return nil if published_at.present? self.published_at = Time.current save! end def destroy force = false return false if published? && !force super() end private def vulgarity_level vulgar_word = "fuck" if (title.present? && title =~ /#{vulgar_word}/i) || (text.present? && text =~ /#{vulgar_word}/i) errors.add :base, "Article contains strong language." end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
loco-rails-0.0.1 | test/dummy/app/models/article.rb |