Sha256: 8f5ec73967a1ae37b70ad41137c94976d06cc875ba866994d6a73e237a9cafdc

Contents?: true

Size: 1023 Bytes

Versions: 1

Compression:

Stored size: 1023 Bytes

Contents

class E9Crm::CampaignsController < E9Crm::ResourcesController
  defaults :resource_class => Campaign
  include E9Rails::Controllers::Orderable

  self.should_paginate_index = false

  has_scope :of_group, :as => :group, :only => :index

  has_scope :active, :only => :index, :default => 'true' do |_, scope, value|
    scope.active(E9.true_value?(value))
  end

  has_scope :of_type, :as => :type, :only => :index do |_, scope, value|
    scope.of_type("#{value}_campaign".classify)
  end

  protected

    def collection_scope
      #end_of_association_chain.typed.includes(:campaign_group)

      # NOTE this is a pretty ugly join just to be able to sort on campaign group name
      end_of_association_chain.typed
        .joins("left outer join campaign_groups on campaign_groups.id = campaigns.campaign_group_id")
        .select("campaigns.*, campaign_groups.name campaign_group_name")
    end

    def default_ordered_on
      'campaign_group_name,name'
    end

    def default_ordered_dir
      'ASC'
    end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
e9_crm-0.1.16 app/controllers/e9_crm/campaigns_controller.rb