-
Notifications
You must be signed in to change notification settings - Fork 617
Expand file tree
/
Copy pathpages_controller.rb
More file actions
74 lines (57 loc) · 1.71 KB
/
pages_controller.rb
File metadata and controls
74 lines (57 loc) · 1.71 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
module Locomotive
class PagesController < BaseController
account_required & within_site
localized
before_action :back_to_default_site_locale, only: %w(new create)
before_action :load_page, only: [:edit, :update, :sort, :destroy]
respond_to :json, only: [:sort]
def new
authorize Page
@page = current_site.pages.build
respond_with @page
end
def create
authorize Page
@page = service.create(page_params)
respond_with @page, location: -> { edit_content_path(@page) }
end
def edit
authorize @page
@page.find_layout
respond_with @page
end
def update
authorize @page
service.update(@page, page_params)
respond_with @page, location: edit_page_path(current_site, @page)
end
def destroy
authorize @page
service.destroy(@page)
respond_with @page, location: dashboard_path(current_site)
end
def sort
authorize @page, :update?
service.sort(@page, params.require(:children))
respond_with @page, location: edit_page_path(current_site, @page)
end
private
def load_page
@page = current_site.pages.find(params[:id])
end
def page_params
params.require(:page).permit(*policy(@page || Page).permitted_attributes)
end
def service
@service ||= Locomotive::PageService.new(current_site, current_locomotive_account, current_content_locale)
end
def edit_content_path(page)
# FIXME: keep the compatibility with the old system using the editable elements
if current_site.sections.count == 0
edit_page_path(current_site, page)
else
edit_page_content_path(current_site, page)
end
end
end
end