Class: Admin::PagesController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#authenticate_user!, #current_user, #load_settings

Instance Method Details

#createObject


23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/admin/pages_controller.rb', line 23

def create
  @page = current_user.pages.build(page_params)

  if @page.save
    redirect_to admin_pages_path, notice: 'Page created!'
  else
    flash.now.alert = 'Error creating page.'
    render :new
  end
end

#editObject


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

def edit
end

#indexObject


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

def index
  @pages = current_user.pages.all
end

#newObject


19
20
21
# File 'app/controllers/admin/pages_controller.rb', line 19

def new
  @page = current_user.pages.build
end

#previewObject


13
14
15
16
17
# File 'app/controllers/admin/pages_controller.rb', line 13

def preview
  markdown = params[:markdown].to_s

  render json: { html: Insomnia::Markdown.render(markdown) }
end

#updateObject


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

def update
  if @page.update(page_params)
    redirect_to admin_pages_path, notice: 'Page updated!'
  else
    flash.now.alert = 'Error updating page.'
    render :edit
  end
end