/
terms_controller.rb
45 lines (37 loc) · 1001 Bytes
/
terms_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
class TermsController < ApplicationController
def show
@term = Term.find(params[:id])
end
def new
@glossary = Glossary.find(params[:glossary_id])
@term = @glossary.new_term
@definition = @term.build_definition
end
def create
@glossary = Glossary.find(params[:glossary_id])
@term = @glossary.terms.build(params[:term])
if @term.save
redirect_to glossary_path(@glossary),
notice: "Term was successfully added to glossary!"
else
render :new
end
end
def edit
@glossary = Glossary.find(params[:glossary_id])
@term = Term.find(params[:id])
end
def update
@term = Term.find(params[:id])
if @term.update_attributes(params[:term])
redirect_to glossary_term_path(@term), notice: "Changes were saved!"
else
render :edit
end
end
def destroy
@term = Term.find(params[:id])
@term.destroy
redirect_to glossary_path(@term.glossary), notice: "Term was successfully deleted!"
end
end