Class: Admin::PostsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/admin/posts_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/posts_controller.rb', line 23

def create
  @post = current_user.posts.build(post_params)

  if @post.save
    redirect_to admin_posts_path, notice: 'Post created!'
  else
    flash.now.alert = 'Error creating post.'
    render :new
  end
end

#editObject


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

def edit
end

#indexObject


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

def index
  @posts = current_user.posts.all
end

#newObject


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

def new
  @post = current_user.posts.build
end

#previewObject


13
14
15
16
17
# File 'app/controllers/admin/posts_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/posts_controller.rb', line 37

def update
  if @post.update(post_params)
    redirect_to admin_posts_path, notice: 'Post updated!'
  else
    flash.now.alert = 'Error updating post.'
    render :edit
  end
end