-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathpages_controller.rb
More file actions
78 lines (66 loc) · 1.61 KB
/
pages_controller.rb
File metadata and controls
78 lines (66 loc) · 1.61 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
class PagesController < ApplicationController
include PageRunners
def show
@wiki, @page = run(Show, params[:wiki_id], params[:id])
end
def show_named
run(ShowNamed, named_params[:wiki], named_params[:page]) do |on|
on.success { |wiki, page|
@wiki = wiki
@page = page
render :show
}
on.page_not_found { |wiki_name|
redirect_to new_named_page_path(wiki_name, named_params[:page])
}
end
end
def new_named
@wiki, @page = run(NewNamed, named_params[:wiki], named_params[:page])
render :new
end
def new
@wiki, @page = run(New, params[:wiki_id], params[:name])
end
def create
run(Create, params[:wiki_id], page_params) do |on|
on.success { |page|
redirect_to [page.wiki, page], notice: "#{page.name} created"
}
on.failure { |wiki, page|
render :new
}
end
end
def edit
@wiki, @page = run(Edit, params[:wiki_id], params[:id])
end
def update
run(Update, params[:wiki_id], params[:id], content_params ) do |on|
on.success { |wiki, page|
redirect_to [wiki, page], notice: "#{page.name} updated"
}
on.failure { |wiki, page|
@wiki = wiki
@page = page
render :new
}
end
end
def destroy
wiki = run(Destroy, params[:wiki_id], params[:id]).first
redirect_to wiki
end
private
def page_params
params.require(:page).permit(:name, :content)
end
def content_params
params.require(:page).permit(:content)
end
def named_params
params.require(:wiki)
params.require(:page)
params
end
end