Sha256: 17393f35e2892464f53544636cbe330afaf32ba02018becc9c08b7406b0c6dfa

Contents?: true

Size: 1020 Bytes

Versions: 6

Compression:

Stored size: 1020 Bytes

Contents

module Ems
  class Channel < ActiveRecord::Base

    attr_accessible :name, :category_ids, :articles, :news, :reports

    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

    has_and_belongs_to_many :categories, :join_table => 'ems_categories_channels'
    accepts_nested_attributes_for :categories

    has_and_belongs_to_many :articles, :join_table => 'ems_articles_channels'
    accepts_nested_attributes_for :articles
    has_and_belongs_to_many :news, :join_table => 'ems_channels_news'
    accepts_nested_attributes_for :news
    has_and_belongs_to_many :reports, :join_table => 'ems_channels_reports'
    accepts_nested_attributes_for :reports


    #
    # @param options
    def as_json(options={})
      super( options.merge( :include => [ :categories, :articles, :reports, :news ] ) )
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ems-0.1.12 app/models/ems/channel.rb
ems-0.1.11 app/models/ems/channel.rb
ems-0.1.10 app/models/ems/channel.rb
ems-0.1.9 app/models/ems/channel.rb
ems-0.1.8 app/models/ems/channel.rb
ems-0.1.7 app/models/ems/channel.rb