Sha256: bb4fc66265b4f35cf7cfb3ecc90044d4ff75d3a268d8b46e19f0acdebb872ebf

Contents?: true

Size: 1.54 KB

Versions: 8

Compression:

Stored size: 1.54 KB

Contents

require "babosa"
include ActionView::Helpers::SanitizeHelper

module C80News
  class Fact < ActiveRecord::Base
    has_many :fphotos, :dependent => :destroy
    accepts_nested_attributes_for :fphotos,
                                  :reject_if => lambda { |attributes|
                                    !attributes.present?
                                  },
                                  :allow_destroy => true

    validates_with FactValidator
    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 fphotos.count > 0
        s = fphotos.first.image.thumb_sm
      end
      s
    end
    
    def thumb_md
      s = ''
      if fphotos.count > 0
        s = fphotos.first.image.thumb_md
      end
      s
    end
    
    def thumb_lg
      s = ''
      if fphotos.count > 0
        s = fphotos.first.image.thumb_lg
      end
      s
    end
    
    def thumb_preview
      s = ''
      if fphotos.count > 0
        s = fphotos.first.image.thumb_preview
      end
      s
    end

  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
c80_news-0.1.0.15 app/models/c80_news/fact.rb
c80_news-0.1.0.14 app/models/c80_news/fact.rb
c80_news-0.1.0.13 app/models/c80_news/fact.rb
c80_news-0.1.0.12 app/models/c80_news/fact.rb
c80_news-0.1.0.11 app/models/c80_news/fact.rb
c80_news-0.1.0.10 app/models/c80_news/fact.rb
c80_news-0.1.0.9 app/models/c80_news/fact.rb
c80_news-0.1.0.8 app/models/c80_news/fact.rb