Class: RecordsController
Instance Method Summary
collapse
#authorize_domain, #current_domain
#current_user
Instance Method Details
#create ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
|
# File 'app/controllers/records_controller.rb', line 12
def create
@domain = Domain.find_by(host: params[:host])
@record = Record.create(domain_id: @domain.id, name: params["name"], type: params["type"], content: params["content"], ttl: params["ttl"], priority: params["priority"]) respond_to do |format|
format.turbo_stream do
render turbo_stream: turbo_stream.append("records", @record)
end
format.html { redirect_to records_url(@domain) }
end
end
|
#destroy ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'app/controllers/records_controller.rb', line 27
def destroy
@record = Record.find(params["id"].to_i)
if @record.nil?
render status: 404, plain: "404 Not Found"
return
end
if @record.domain_id != Domain.find_by(host: params[:host])&.id
render status: 403, plain: "403 Forbidden"
end
@domain = Domain.find_by(host: params["host"])
id = @record.id
@record.destroy!
respond_to do |format|
format.turbo_stream do
render turbo_stream: turbo_stream.remove("record_#{id}")
end
format.html { redirect_to records_url(@domain) }
end
end
|
#edit ⇒ Object
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'app/controllers/records_controller.rb', line 77
def edit
@record = Record.find(params["id"].to_i)
if @record.nil?
render status: 404, plain: "404 Not Found"
return
end
if @record.domain_id != Domain.find_by(host: params[:host])&.id
render status: 403, plain: "403 Forbidden"
end
@domain = Domain.find_by(host: params["host"])
render turbo_stream: turbo_stream.replace("record_#{@record.id}", partial: "edit", locals: {record: @record})
end
|
#index ⇒ Object
7
8
9
10
|
# File 'app/controllers/records_controller.rb', line 7
def index
@records = Record.where_host(params[:host])
@domain = Domain.find_by(host: params["host"])
end
|
#new ⇒ Object
24
25
|
# File 'app/controllers/records_controller.rb', line 24
def new
end
|
#show ⇒ Object
94
95
96
97
98
99
100
101
102
103
104
105
|
# File 'app/controllers/records_controller.rb', line 94
def show
@record = Record.find(params["id"].to_i)
if @record.nil?
render status: 404, plain: "404 Not Found"
return
end
if @record.domain_id != Domain.find_by(host: params[:host])&.id
render status: 403, plain: "403 Forbidden"
end
@domain = Domain.find_by(host: params["host"])
end
|
#update ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'app/controllers/records_controller.rb', line 52
def update
@record = Record.find(params["id"].to_i)
@domain = Domain.find_by(host: params["host"])
if @record.nil?
render status: 404, plain: "404 Not Found"
return
end
if @record.domain_id != Domain.find_by(host: params[:host])&.id
render status: 403, plain: "403 Forbidden"
end
@record.update(params.permit(:type, :name, :content, :ttl, :priority))
@record.save
respond_to do |format|
format.turbo_stream do
render turbo_stream: turbo_stream.replace("records", @record)
end
format.html { redirect_to records_url(@domain) }
end
end
|