Class: CustomerVault::LinksController

Inherits:
ApplicationController show all
Defined in:
app/controllers/customer_vault/links_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/customer_vault/links_controller.rb', line 20

def create
  authorize! :update, @person

  params = link_params
  bob = params[:bob].split("-")

  @link ||= Link.new(title: params[:title], alice_id: @person.id, alice_type: @person.class.to_s, bob_id: bob[1], bob_type: bob[0])

  if @link.save
    flash[:notice] = 'Link was successfully created.'
    redirect_to url_for(@person) + "#links"
  else
    render :new
  end
end

#destroyObject



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/controllers/customer_vault/links_controller.rb', line 49

def destroy
  authorize! :update, @person

  @link = Link.find(params[:id])

  if @link.destroy
    flash[:notice] = 'Individual was successfully destroyed.'
  else
    flash[:alert] = 'Individual was NOT destroyed.'
  end

  redirect_to url_for(@person) + "#links"
end

#editObject



14
15
16
17
18
# File 'app/controllers/customer_vault/links_controller.rb', line 14

def edit
  authorize! :update, @person

  @link = Link.find(params[:id])
end

#newObject



7
8
9
10
11
12
# File 'app/controllers/customer_vault/links_controller.rb', line 7

def new
  authorize! :update, @person

  @link   ||= Link.new
  @people ||= Person.list
end

#updateObject



36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/customer_vault/links_controller.rb', line 36

def update
  authorize! :update, @person

  @link = Link.find(params[:id])

  if @link.update(link_params)
    flash[:notice] = 'Link was successfully updated.'
    redirect_to url_for(@person) + "#links"
  else
    render :edit
  end
end