Class: Stiki::PagesController

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

Instance Method Summary collapse

Methods included from ApplicationHelper

#has_access, #stiki_routes, #user_name

Instance Method Details

#createObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/stiki/pages_controller.rb', line 38

def create
  @page = Page.new(params[:page])
  @page.space = @space
  
  if Stiki.authenticate_by == :devise
    author = Author.new
    author.user = self.send( "current_#{Stiki::Helper.user_model_name}".to_sym )
    author.creator = true
    @page.authors << author
  end
  
  if @page.save
    redirect_to stiki_routes.space_page_path(@space, @page)
  else
    flash[:error] = "Error creating Page"
    render "stiki/pages/new"
  end
end

#destroyObject



77
78
79
80
81
82
83
# File 'app/controllers/stiki/pages_controller.rb', line 77

def destroy
  @page = Page.find( params[:id] )
  
  @page.destroy
  
  redirect_to stiki_routes.space_pages_path(@space)
end

#editObject



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

def edit
  @page = Page.find( params[:id] )
  
end

#indexObject



8
9
10
11
# File 'app/controllers/stiki/pages_controller.rb', line 8

def index
  @spaces = Space.all
  @pages = @space.pages
end

#newObject



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

def new
  @page = Page.new
end

#showObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/stiki/pages_controller.rb', line 13

def show
  @spaces = Space.all
  @pages = @space.pages
  
  @page = Page.find_by_slug( params[:id] )
  
  if @page.nil?
    flash[:error] = "Wiki Pages does not exist: #{params[:id]}"
    redirect_to stiki_routes.space_pages_path(@space)
  else
    markdown = Kramdown::Document.new(@page.body)
    
    @markup = markdown.to_html.html_safe
  end
end

#updateObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/controllers/stiki/pages_controller.rb', line 57

def update
  @page = Page.find( params[:id] )
  
  @page.attributes = params[:page]
  
  if Stiki.authenticate_by == :devise
    author = Author.new
    author.user = self.send( "current_#{Stiki::Helper.user_model_name}".to_sym )
    @page.authors << author
  end
  
  if @page.save
    @page.mark_badges
    redirect_to stiki_routes.space_page_path(@space, @page)
  else
    flash[:error] = "Error editing Page"
    render "stiki/pages/edit"
  end
end