Class: IshManager::LeadsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/ish_manager/leads_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#home

Instance Method Details

#bulkopObject

alphabetized : )



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/ish_manager/leads_controller.rb', line 8

def bulkop
  authorize! :bulkop, ::Lead
  case params[:a]
  when 'add_to_campaign'
    c = EmailCampaign.find params[:email_campaign_id]
    params[:lead_ids].each do |lead_id|
      c_lead = EmailCampaignLead.new( lead_id: lead_id, email_campaign_id: c.id )
      flag = c_lead.save
      if !flag
        puts! c_lead.errors.full_messages.join(", ")
      end
    end
    flash[:notice] = 'Done acted; See logs.'
    redirect_to action: :index
  end
end

#createObject



25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/ish_manager/leads_controller.rb', line 25

def create
  @lead = ::Lead.new params[:lead].permit!
  authorize! :create, @lead
  if @lead.save
    flash[:notice] = "created lead"
  else
    flash[:alert] = "Cannot create lead: #{@lead.errors.messages}"
  end
  redirect_to :action => 'index'
end

#editObject



36
37
38
39
# File 'app/controllers/ish_manager/leads_controller.rb', line 36

def edit
  @lead = ::Lead.find params[:id]
  authorize! :edit, @lead
end

#indexObject



41
42
43
44
# File 'app/controllers/ish_manager/leads_controller.rb', line 41

def index
  authorize! :index, ::Lead
  @leads = ::Lead.all.includes( :leadset )
end

#newObject



46
47
48
49
# File 'app/controllers/ish_manager/leads_controller.rb', line 46

def new
  @new_lead = ::Lead.new
  authorize! :new, @new_lead
end

#showObject



51
52
53
54
# File 'app/controllers/ish_manager/leads_controller.rb', line 51

def show
  authorize! :redirect, IshManager::Ability
  redirect_to :action => :edit, :id => params[:id]
end

#updateObject



56
57
58
59
60
61
62
63
64
65
# File 'app/controllers/ish_manager/leads_controller.rb', line 56

def update
  @lead = ::Lead.find params[:id]
  authorize! :update, @lead
  if @lead.update_attributes params[:lead].permit!
    flash[:notice] = 'Successfully updated lead.'
  else
    flash[:alert] = "Cannot update lead: #{@lead.errors.messages}"
  end
  redirect_to :action => 'index'
end