Class: Documentation::PagesController

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

Instance Method Summary collapse

Instance Method Details

#destroyObject



41
42
43
44
45
# File 'app/controllers/documentation/pages_controller.rb', line 41

def destroy
  authorizer.check! :delete_page, @page
  @page.destroy
  redirect_to @page.parent ? page_path(@page.parent.full_permalink) : root_path, :notice => "Page has been removed successfully."
end

#editObject



10
11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/documentation/pages_controller.rb', line 10

def edit
  authorizer.check! :edit_page, @page
  
  if request.patch?
    if @page.update_attributes(safe_params)
      redirect_to page_path(@page.full_permalink), :notice => "Page has been saved successfully."
      return
    end
  end
  render :action => "form"
end

#newObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/documentation/pages_controller.rb', line 22

def new
  authorizer.check! :add_page, @page
  
  parent = @page
  @page = Page.new(:title => "Untitled Page")
  if @page.parent = parent
    @page.parents = parent.breadcrumb
  end

  if request.post?
    @page.attributes = safe_params
    if @page.save
      redirect_to page_path(@page.full_permalink), :notice => "Page created successfully"
      return
    end
  end
  render :action => "form"
end

#positioningObject



62
63
64
65
66
67
68
69
# File 'app/controllers/documentation/pages_controller.rb', line 62

def positioning
  authorizer.check! :reposition_page, @page
  @pages = @page ? @page.children : Page.roots
  if request.post?
    Page.reorder(@page, params[:order])
    render :json => {:status => 'ok'}
  end
end

#screenshotObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/controllers/documentation/pages_controller.rb', line 47

def screenshot
  authorizer.check! :upload, @page
  if request.post?
    @screenshot = Screenshot.new(screenshot_params)
    if @screenshot.save
      render :json => { :id => @screenshot.id, :title => @screenshot.alt_text, :path => @screenshot.upload.path }, :status => :created
    else
      render :json => { :errors => @screenshot.errors }, :status => :unprocessible_entity
    end
  else
    @screenshot = Screenshot.new
    render 'screenshot', :layout => false
  end
end

#searchObject



71
72
73
74
# File 'app/controllers/documentation/pages_controller.rb', line 71

def search
  authorizer.check! :search
  @result = Documentation::Page.search(params[:query], :page => params[:page].blank? ? 1 : params[:page].to_i)
end

#showObject



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

def show
  authorizer.check! :view_page, @page
end