Sha256: c42c88a4eba0162f49318b495d68fa197342b7a3550f2f137796afe1f324efd5

Contents?: true

Size: 1.43 KB

Versions: 13

Compression:

Stored size: 1.43 KB

Contents

require "babosa"
module C80NewsTz
  class Notice < ActiveRecord::Base
    has_one :gallery, :dependent => :destroy
    accepts_nested_attributes_for :gallery,
                                  :reject_if => lambda { |attributes|
                                    !attributes.present?
                                  },
                                  :allow_destroy => true
    has_one :adress, :dependent => :destroy
    accepts_nested_attributes_for :adress,
                                  :reject_if => lambda { |attributes|
                                    !attributes.present?
                                  },
                                  :allow_destroy => true
    has_many :nphotos, :dependent => :destroy
    accepts_nested_attributes_for :nphotos,
                                  :reject_if => lambda { |attributes|
                                    !attributes.present?
                                  },
                                  :allow_destroy => true
    has_and_belongs_to_many :companies, :join_table => 'c80_news_tz_companies_notices'

    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 should_generate_new_friendly_id?
      slug.blank?
      # name_changed? || super
    end

  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
c80_news_tz-0.1.1.26 app/models/c80_news_tz/notice.rb
c80_news_tz-0.1.1.25 app/models/c80_news_tz/notice.rb
c80_news_tz-0.1.1.24 app/models/c80_news_tz/notice.rb
c80_news_tz-0.1.1.23 app/models/c80_news_tz/notice.rb
c80_news_tz-0.1.1.22 app/models/c80_news_tz/notice.rb
c80_news_tz-0.1.1.21 app/models/c80_news_tz/notice.rb
c80_news_tz-0.1.1.19 app/models/c80_news_tz/notice.rb
c80_news_tz-0.1.1.18 app/models/c80_news_tz/notice.rb
c80_news_tz-0.1.1.17 app/models/c80_news_tz/notice.rb
c80_news_tz-0.1.1.16 app/models/c80_news_tz/notice.rb
c80_news_tz-0.1.1.15 app/models/c80_news_tz/notice.rb
c80_news_tz-0.1.1.1 app/models/c80_news_tz/notice.rb
c80_news_tz-0.1.1.0 app/models/c80_news_tz/notice.rb