Class: FinePrint::ContractsController

Inherits:
ApplicationController show all
Includes:
ApplicationHelper
Defined in:
app/controllers/fine_print/contracts_controller.rb

Instance Method Summary collapse

Methods included from ApplicationHelper

#merge_errors_for

Instance Method Details

#createObject



22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/fine_print/contracts_controller.rb', line 22

def create
  @contract = Contract.new
  @contract.name = params[:contract][:name]
  @contract.title = params[:contract][:title]
  @contract.content = params[:contract][:content]

  if @contract.save
    redirect_to @contract, notice: t('fine_print.contract.notices.created')
  else
    render action: 'new', alert: merge_errors_for(@contract)
  end
end

#destroyObject



56
57
58
59
60
61
62
63
# File 'app/controllers/fine_print/contracts_controller.rb', line 56

def destroy
  if @contract.destroy
    redirect_to contracts_path,
                notice: t('fine_print.contract.notices.deleted')
  else
    redirect_to contracts_path, alert: merge_errors_for(@contract)
  end
end

#editObject



38
39
40
41
42
# File 'app/controllers/fine_print/contracts_controller.rb', line 38

def edit
  @contract.no_signatures
  redirect_to contracts_path, alert: merge_errors_for(@contract) \
    unless @contract.errors.empty?
end

#indexObject



7
8
9
10
11
12
13
14
15
16
# File 'app/controllers/fine_print/contracts_controller.rb', line 7

def index
  @contracts = Contract.select(
    "      \"fine_print_contracts\".*, (\n        SELECT COUNT(*) FROM \"fine_print_signatures\"\n        WHERE \"fine_print_signatures\".\"contract_id\" = \"fine_print_contracts\".\"id\"\n      ) AS \"signatures_count\"\n    EOS\n  ).all.to_a.group_by(&:name)\nend\n"

#newObject



18
19
20
# File 'app/controllers/fine_print/contracts_controller.rb', line 18

def new
  @contract = Contract.new
end

#new_versionObject



83
84
85
# File 'app/controllers/fine_print/contracts_controller.rb', line 83

def new_version
  @contract = @contract.new_version
end

#publishObject



65
66
67
68
69
70
71
72
# File 'app/controllers/fine_print/contracts_controller.rb', line 65

def publish
  if @contract.publish
    redirect_to contracts_path,
                notice: t('fine_print.contract.notices.published')
  else
    redirect_to contracts_path, alert: merge_errors_for(@contract)
  end
end

#showObject



35
36
# File 'app/controllers/fine_print/contracts_controller.rb', line 35

def show
end

#unpublishObject



74
75
76
77
78
79
80
81
# File 'app/controllers/fine_print/contracts_controller.rb', line 74

def unpublish
  if @contract.unpublish
    redirect_to contracts_path,
                notice: t('fine_print.contract.notices.unpublished')
  else
    redirect_to contracts_path, alert: merge_errors_for(@contract)
  end
end

#updateObject



44
45
46
47
48
49
50
51
52
53
54
# File 'app/controllers/fine_print/contracts_controller.rb', line 44

def update
  @contract.name = params[:contract][:name]
  @contract.title = params[:contract][:title]
  @contract.content = params[:contract][:content]

  if @contract.save
    redirect_to @contract, notice: t('fine_print.contract.notices.updated')
  else
    render action: 'edit', alert: merge_errors_for(@contract)
  end
end