Sha256: c6d9e5a2df672a8001d126d419686f3a2d3a6b1d17838b0bf99952874e9b94a9

Contents?: true

Size: 1.57 KB

Versions: 13

Compression:

Stored size: 1.57 KB

Contents

require 'babosa'
include ActionView::Helpers::SanitizeHelper

module Ti
  class Doc < ActiveRecord::Base
    has_many :dphotos, :dependent => :destroy
    accepts_nested_attributes_for :dphotos,
                                  :reject_if => lambda { |attributes|
                                    !attributes.present?
                                  },
                                  :allow_destroy => true
    has_and_belongs_to_many :categories
    validates_with DocValidator
    default_scope {order(:created_at => :desc)}

    extend FriendlyId
    friendly_id :title, use: :slugged
    def normalize_friendly_id(input)
      input.to_s.to_slug.normalize(transliterations: :russian).to_s
    end

    def slug_candidates
      [:title] + Array.new(6) {|index| [:title, index+2]}
    end

    def short_meta_description

      if description.present? && description.length > 200
        result = description
      elsif full.present? && full.length > 0
        result = strip_tags(full[0..200]+'...')
      else
        result = nil
      end
      result

    end

    def thumb_sm
      s = ''
      if dphotos.count > 0
        s = dphotos.first.image.thumb_sm
      end
      s
    end
    
    def thumb_md
      s = ''
      if dphotos.count > 0
        s = dphotos.first.image.thumb_md
      end
      s
    end
    
    def thumb_lg
      s = ''
      if dphotos.count > 0
        s = dphotos.first.image.thumb_lg
      end
      s
    end
    
    def thumb_preview
      s = ''
      if dphotos.count > 0
        s = dphotos.first.image.thumb_preview
      end
      s
    end

  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
c80_yax-0.1.0.22 engines/ti/app/models/ti/doc.rb
c80_yax-0.1.0.21 engines/ti/app/models/ti/doc.rb
c80_yax-0.1.0.20 engines/ti/app/models/ti/doc.rb
c80_yax-0.1.0.18 engines/ti/app/models/ti/doc.rb
c80_yax-0.1.0.17 engines/ti/app/models/ti/doc.rb
c80_yax-0.1.0.16 engines/ti/app/models/ti/doc.rb
c80_yax-0.1.0.15 engines/ti/app/models/ti/doc.rb
c80_yax-0.1.0.14 engines/ti/app/models/ti/doc.rb
c80_yax-0.1.0.13 engines/ti/app/models/ti/doc.rb
c80_yax-0.1.0.12 engines/ti/app/models/ti/doc.rb
c80_yax-0.1.0.11 engines/ti/app/models/ti/doc.rb
c80_yax-0.1.0.10 engines/ti/app/models/ti/doc.rb
c80_yax-0.1.0.9 engines/ti/app/models/ti/doc.rb