Class: Pageflow::PagesController

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

Instance Method Summary collapse

Instance Method Details

#createObject


7
8
9
10
11
12
13
14
15
16
# File 'app/controllers/pageflow/pages_controller.rb', line 7

def create
  chapter = Chapter.find(params[:chapter_id])
  page = chapter.pages.build(page_params)

  authorize!(:create, page)
  verify_edit_lock!(page.chapter.entry)
  page.save

  respond_with(page)
end

#destroyObject


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

def destroy
  page = Page.find(params[:id])

  authorize!(:destroy, page)
  verify_edit_lock!(page.chapter.entry)
  page.chapter.entry.snapshot(:creator => current_user)

  page.destroy

  respond_with(page)
end

#orderObject


28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/pageflow/pages_controller.rb', line 28

def order
  chapter = Chapter.find(params[:chapter_id])
  entry = DraftEntry.new(chapter.entry)

  authorize!(:edit_outline, entry.to_model)
  verify_edit_lock!(chapter.entry)
  params.require(:ids).each_with_index do |id, index|
    entry.pages.update(id, :chapter_id => chapter.id, :position => index)
  end

  head :no_content
end

#updateObject


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

def update
  page = Page.find(params[:id])

  authorize!(:update, page)
  verify_edit_lock!(page.chapter.entry)
  page.update_attributes(page_params)

  respond_with(page)
end