74cbca706b
- All models: SimplyStored::Couch → SimplyCouch::Model - Gemfile: simply_stored → simply_couch - devise_simply_stored → devise_simply_couch - Remove stale couch_potato require (not used)
36 lines
1.2 KiB
Ruby
36 lines
1.2 KiB
Ruby
module Cmtool
|
|
class News
|
|
include SimplyCouch::Model
|
|
include Paperclip::Glue
|
|
# TODO: Replace Paperclip with SimplyCouch::HasAttachment
|
|
# 1. Change `include Paperclip::Glue` to `include SimplyCouch::HasAttachment`
|
|
# 2. Replace `has_attached_file :image, styles: {...}` with `has_attachment :image, styles: {...}`
|
|
|
|
property :title
|
|
property :active, type: :boolean, default: true
|
|
property :date, type: Date
|
|
property :body
|
|
|
|
property :image_file_name
|
|
property :image_content_type
|
|
property :image_file_size, type: Integer
|
|
property :image_updated_at, type: Time
|
|
|
|
has_attached_file :image, styles: { :medium => "500x500>", :thumb => "250x250>" }
|
|
has_and_belongs_to_many :keywords, storing_keys: true
|
|
validates :title, presence: true
|
|
validates :date, presence: true
|
|
|
|
view :all_documents, key: :date, descending: true
|
|
view :by_active, key: [:active, :date], descending: true
|
|
|
|
def self.active(options = {till: Date.today})
|
|
find_all_by_active(true, options)
|
|
end
|
|
|
|
def self.find_all_by_active(active, options = {till: Date.today})
|
|
database.view(by_active(startkey: [active, options[:till].strftime('%Y-%m-%d')], endkey: [active], descending: true))
|
|
end
|
|
end
|
|
end
|