Class: Admin::PagesController

Inherits:
AdminController show all
Includes:
PagesCore::PageParameters
Defined in:
app/controllers/admin/pages_controller.rb

Instance Attribute Summary

Attributes included from PagesCore::Authentication

#current_user

Instance Method Summary collapse

Methods included from PagesCore::PageParameters

#page_attachment_attributes, #page_content_attributes, #page_static_attributes

Methods inherited from PagesCore::AdminController

#redirect, underscore

Methods included from PagesCore::StaticCacheController

#disable_static_cache!, #static_cached?

Methods included from PagesCore::PoliciesHelper

#policy, #verify_policy, #verify_policy_with_proc

Methods included from PagesCore::ProcessTitler

inc_number_of_requests, original_title

Methods included from PagesCore::LocalesHelper

#content_locale

Methods included from PagesCore::ErrorRenderer

#render_error

Methods included from PagesCore::Authentication

#authenticate!, #deauthenticate!, #logged_in?

Instance Method Details

#createObject



40
41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/admin/pages_controller.rb', line 40

def create
  @page = build_page(content_locale, page_params).tap(&:save)

  respond_with_page(@page) do
    if @page.valid?
      redirect_to(edit_admin_page_url(content_locale, @page))
    else
      render action: :new
    end
  end
end

#deletedObject



15
16
17
# File 'app/controllers/admin/pages_controller.rb', line 15

def deleted
  @pages = Page.deleted.by_updated_at.in_locale(content_locale)
end

#destroyObject



70
71
72
73
# File 'app/controllers/admin/pages_controller.rb', line 70

def destroy
  Page.find(params[:id]).flag_as_deleted!
  redirect_to admin_pages_url(content_locale)
end

#editObject



38
# File 'app/controllers/admin/pages_controller.rb', line 38

def edit; end

#indexObject



11
12
13
# File 'app/controllers/admin/pages_controller.rb', line 11

def index
  @pages = Page.admin_list(content_locale)
end

#moveObject



64
65
66
67
68
# File 'app/controllers/admin/pages_controller.rb', line 64

def move
  parent = params[:parent_id] ? Page.find(params[:parent_id]) : nil
  @page.update(parent:, position: params[:position])
  respond_with_page(@page) { redirect_to admin_pages_url(content_locale) }
end

#newObject



32
33
34
35
36
# File 'app/controllers/admin/pages_controller.rb', line 32

def new
  build_params = params[:page] ? page_params : nil
  @page = build_page(content_locale, build_params)
  @page.parent = Page.find_by(id: params[:parent])
end

#searchObject



19
20
21
22
23
24
25
26
# File 'app/controllers/admin/pages_controller.rb', line 19

def search
  return if search_query.blank?

  @search_documents =
    SearchDocument.where(searchable_type: "Page")
                  .search(search_query, locale: content_locale)
                  .paginate(per_page: 50, page: params[:page])
end

#showObject



28
29
30
# File 'app/controllers/admin/pages_controller.rb', line 28

def show
  redirect_to edit_admin_page_url(content_locale, @page)
end

#updateObject



52
53
54
55
56
57
58
59
60
61
62
# File 'app/controllers/admin/pages_controller.rb', line 52

def update
  @page.update(page_params)
  respond_with_page(@page) do
    if @page.valid?
      flash[:notice] = t("pages_core.changes_saved")
      redirect_to edit_admin_page_url(content_locale, @page)
    else
      render action: :edit
    end
  end
end