Class: Kms::PagesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/kms/pages_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#set_csrf_cookie_for_ng

Instance Method Details

#createObject



10
11
12
13
14
15
16
17
# File 'app/controllers/kms/pages_controller.rb', line 10

def create
  @page = Page.new(page_params)
  if @page.save
    head :no_content
  else
    render json: { errors: @page.errors.full_messages }.to_json, status: :unprocessable_entity
  end
end

#destroyObject



33
34
35
36
37
# File 'app/controllers/kms/pages_controller.rb', line 33

def destroy
  @page = Page.find(params[:id])
  @page.destroy
  head :no_content
end

#indexObject



6
7
8
# File 'app/controllers/kms/pages_controller.rb', line 6

def index
  render json: Page.arrange_serializable(order: :position)
end

#showObject



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

def show
  @page = Page.find(params[:id])
  render json: @page
end

#sortingObject



39
40
41
42
43
44
45
46
47
# File 'app/controllers/kms/pages_controller.rb', line 39

def sorting
  params["_json"].each_with_index do |page, index|
    p = Page.find_by_id(page["id"])
    p.update_attribute(:parent_id, nil)
    p.update_attribute(:position, index)
    sort(page["id"], page["children"]) if page["children"].present?
  end
  render json: Page.arrange_serializable(order: :position)
end

#updateObject



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

def update
  @page = Page.find(params[:id])
  if @page.update(page_params)
    head :no_content
  else
    render json: { errors: @page.errors.full_messages }.to_json, status: :unprocessable_entity
  end
end