forked from chicago-tool-library/circulate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotes_controller.rb
49 lines (39 loc) · 1.15 KB
/
notes_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
class Admin::NotesController < ApplicationController
include ActionView::RecordIdentifier
include PortalRendering
before_action :load_parent
def create
@note = @parent.notes.create(note_params.merge(creator: current_user))
if @note.save
redirect_to [:admin, @parent, anchor: dom_id(@note)]
else
render_to_portal "form", locals: {parent: @parent, note: @note}, status: 422
end
end
def update
@note = @parent.notes.find(params[:id])
if @note.update(note_params)
redirect_to [:admin, @parent, anchor: dom_id(@note)]
else
render_to_portal "form", locals: {parent: @parent, note: @note}, status: 422
end
end
def edit
@note = @parent.notes.find(params[:id])
render_to_portal "form", locals: {parent: @parent, note: @note}
end
def show
@note = @parent.notes.find(params[:id])
render_to_portal "show", locals: {parent: @parent, note: @note}
end
private
def note_params
params.require(:note).permit(:body)
end
def load_parent
@parent = if params[:item_id]
Item.find(params[:item_id])
end
raise ActiveRecord::RecordNotFound unless @parent
end
end