-
Notifications
You must be signed in to change notification settings - Fork 344
/
programs_controller.rb
62 lines (49 loc) · 1.29 KB
/
programs_controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
class Admin
class ProgramsController < ApplicationController
before_action :authenticate_admin!
layout 'admin'
def index
@programs = Kaminari.paginate_array(policy_scope(Program)).
page(params[:page]).per(params[:per_page])
end
def edit
@program = Program.find(params[:id])
authorize @program
end
def update
@program = Program.find(params[:id])
authorize @program
if @program.update(program_params)
redirect_to [:admin, @program],
notice: 'Program was successfully updated.'
else
render :edit
end
end
def new
@program = Program.new
authorize @program
end
def create
@program = Program.new(program_params)
org = @program.organization
authorize @program if org.present?
if @program.save
redirect_to admin_programs_url,
notice: 'Program was successfully created.'
else
render :new
end
end
def destroy
program = Program.find(params[:id])
authorize program
program.destroy
redirect_to admin_programs_path
end
private
def program_params
params.require(:program).permit(:alternate_name, :name, :organization_id)
end
end
end