Class: PagesController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#fresh_when, #redirect_back_or_default, #redirect_referrer_or_default, #render_403, #render_404, #render_optional_error_file, #require_user, #set_active_menu, #set_locale, #set_seo_meta, #store_location, #unread_notify_count

Instance Method Details

#commentsObject


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

def comments
  @page = Page.find_by_slug(params[:id])
  render_404 if @page.blank?
end

#createObject


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

def create
  @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


48
49
50
51
# File 'app/controllers/pages_controller.rb', line 48

def edit
  @page = Page.find_by_slug(params[:id])
  set_seo_meta t('pages.edit_wiki_page')
end

#indexObject


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

def index
  set_seo_meta('Wiki')

  fresh_when(etag: [Setting.wiki_index_html])
end

#newObject


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

def new
  @page = Page.new
  @page.slug = params[:title]
  set_seo_meta t('pages.new_wiki_page')
  respond_to do |format|
    format.html # new.html.erb
    format.json { render json: @page }
  end
end

#previewObject


77
78
79
# File 'app/controllers/pages_controller.rb', line 77

def preview
  render plain: MarkdownTopicConverter.convert(params[:body])
end

#recentObject


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

def recent
  @pages = Page.recent.paginate(page: params[:page], per_page: 30)
  set_seo_meta t('pages.wiki_index')

  fresh_when(etag: [@pages])
end

#showObject


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

def show
  @page = Page.find_by_slug(params[:id])
  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

  set_seo_meta("#{@page.title} - Wiki")
  fresh_when(etag: [@page, @page.comments_count])
end

#updateObject


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

def update
  @page = Page.find_by_slug(params[:id])
  @page.version_enable = true
  @page.user_id = current_user.id

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