Sha256: 6fc2e0d74c24d0ece45ee9635a92613c483bab22daf5022e9991e8ad5fef2520

Contents?: true

Size: 688 Bytes

Versions: 8

Compression:

Stored size: 688 Bytes

Contents

module Ems
  class Category < ActiveRecord::Base
    # use friendly_id to handle our slugs
    extend FriendlyId
    friendly_id :name, use: :slugged
    def should_generate_new_friendly_id?
      new_record?
    end

    # Validators
    validates_uniqueness_of :slug
    validates :slug, :presence => true
    validates :name, :presence => true
    validates :strapline, :presence => true

    # relations
    has_and_belongs_to_many :channels, :join_table => 'ems_categories_channels'
    accepts_nested_attributes_for :channels
    has_many :articles

    #
    # @param options
    def as_json(options={})
      super( options.merge( :include => [ :channels ] ) )
    end

  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
ems-0.1.6 app/models/ems/category.rb
ems-0.1.5 app/models/ems/category.rb
ems-0.1.4 app/models/ems/category.rb
ems-0.1.3 app/models/ems/category.rb
ems-0.1.2 app/models/ems/category.rb
ems-0.1.1 app/models/ems/category.rb
ems-0.1.0 app/models/ems/category.rb
ems-0.0.9 app/models/ems/category.rb