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

#createObject



19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/ish_manager/leads_controller.rb', line 19

def create
  @lead = Ish::Lead.new params[:lead].permit!
  @lead.profile = current_user.profile
  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 = Ish::Lead.find params[:id]
  authorize! :edit, @lead
end

#indexObject



3
4
5
6
7
8
9
10
11
12
# File 'app/controllers/ish_manager/leads_controller.rb', line 3

def index
  authorize! :index, Ish::Lead
  @leads = Ish::Lead.where( :profile => current_user.profile, :is_trash => false )
  if params[:is_done]
    @leads = @leads.where( :is_done => true )
  else
    @leads = @leads.where( :is_done => false )
  end
  render :layout => 'ish_manager/application_no_materialize'
end

#newObject



14
15
16
17
# File 'app/controllers/ish_manager/leads_controller.rb', line 14

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

#showObject



31
32
33
34
# File 'app/controllers/ish_manager/leads_controller.rb', line 31

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

#updateObject



41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/ish_manager/leads_controller.rb', line 41

def update
  @lead = Ish::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