Class: Homeland::Wiki::PagesController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#current_ability

Instance Method Details

#commentsObject



32
33
34
# File 'app/controllers/homeland/wiki/pages_controller.rb', line 32

def comments
  render_404 if @page.blank?
end

#createObject



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

def create
  authorize! :create, Page

  @page = Page.new(page_params)
  @page.user_id = current_user.id
  @page.version_enable = true

  if @page.save
    redirect_to page_path(@page.slug), notice: t('common.create_success')
  else
    render action: 'new'
  end
end

#editObject



47
48
49
# File 'app/controllers/homeland/wiki/pages_controller.rb', line 47

def edit
  authorize! :edit, @page
end

#indexObject



8
9
10
# File 'app/controllers/homeland/wiki/pages_controller.rb', line 8

def index
  fresh_when(Setting.wiki_index_html)
end

#newObject



36
37
38
39
40
41
42
43
44
45
# File 'app/controllers/homeland/wiki/pages_controller.rb', line 36

def new
  authorize! :create, Page

  @page = Page.new
  @page.slug = params[:title]
  respond_to do |format|
    format.html # new.html.erb
    format.json { render json: @page }
  end
end

#previewObject



78
79
80
# File 'app/controllers/homeland/wiki/pages_controller.rb', line 78

def preview
  render plain: Homeland::Markdown.call(params[:body])
end

#recentObject



12
13
14
15
# File 'app/controllers/homeland/wiki/pages_controller.rb', line 12

def recent
  @pages = Page.recent.page(params[:page])
  fresh_when(@pages)
end

#showObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/homeland/wiki/pages_controller.rb', line 17

def show
  if @page.blank?
    if current_user.blank?
      render_404
      return
    end

    redirect_to new_page_path(title: params[:id]), notice: 'Page not Found, Please create a new page'
    return
  end

  @page.hits.incr(1)
  fresh_when(@page)
end

#updateObject



65
66
67
68
69
70
71
72
73
74
75
76
# File 'app/controllers/homeland/wiki/pages_controller.rb', line 65

def update
  authorize! :update, @page

  @page.version_enable = true
  @page.user_id = current_user.id

  if @page.update(page_params)
    redirect_to page_path(@page.slug), notice: t('common.update_success')
  else
    render action: 'edit'
  end
end