Sha256: 70fecf604d43ecb00603174196190932f2721623c41142bfc6d5adda291ebe69

Contents?: true

Size: 705 Bytes

Versions: 8

Compression:

Stored size: 705 Bytes

Contents

module PagesCms
  class Article < ActiveRecord::Base

    belongs_to :image

    validates :title,   presence: true
    validates :content, presence: true
    validates :tags,    presence: true


    def tags=(val)
      write_attribute(:tags, val.split(',') )
    end

    scope :search, -> (search)  { where('content ILIKE ? OR tags @> ? OR title ILIKE ? ',"#{search}",'{' + search + '}',"#{search}") }
    scope :status, -> (status) do
      case status
        when 'Archived'
          where(archived: true)
        when 'Drafts'
          where(draft: true)
        when 'Published'
          where('draft = ? AND archived = ?', false, false)
        else
          all
      end
    end

  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
pages_cms-1.0.3 app/models/pages_cms/article.rb
pages_cms-1.0.2 app/models/pages_cms/article.rb
pages_cms-1.0.1 app/models/pages_cms/article.rb
pages_cms-1.0.0 app/models/pages_cms/article.rb
pages_cms-0.2.3 app/models/pages_cms/article.rb
pages_cms-0.2.2 app/models/pages_cms/article.rb
pages_cms-0.2.1 app/models/pages_cms/article.rb
pages_cms-0.2.0 app/models/pages_cms/article.rb