Class: Monologue::Admin::PostsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/monologue/admin/posts_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



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

def create
  @post = Monologue::Post.new post_params
  @post.user_id = monologue_current_user.id
  if @post.save
    prepare_flash_and_redirect_to_edit()
  else
    render :new
  end
end

#destroyObject



45
46
47
48
49
50
51
52
# File 'app/controllers/monologue/admin/posts_controller.rb', line 45

def destroy
  post = Monologue::Post.find(params[:id])
  if post.destroy
    redirect_to admin_posts_path, notice:  I18n.t("monologue.admin.posts.delete.removed")
  else
    redirect_to admin_posts_path, alert: I18n.t("monologue.admin.posts.delete.failed")
  end
end

#editObject



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

def edit
end

#indexObject



5
6
7
8
# File 'app/controllers/monologue/admin/posts_controller.rb', line 5

def index
  @page = params[:page].nil? ? 1 : params[:page]
  @posts = Monologue::Post.listing_page(@page).includes(:user)
end

#newObject



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

def new
  @post = Monologue::Post.new
end

#previewObject

Preview a post without saving.



15
16
17
18
19
20
21
22
# File 'app/controllers/monologue/admin/posts_controller.rb', line 15

def preview
  # mockup our models for preview.
  @post = Monologue::Post.new post_params
  @post.user_id = monologue_current_user.id
  @post.published_at = Time.zone.now
  # render it exactly as it would display when live.
  render "/monologue/posts/show", layout: Monologue::Config.layout || "/layouts/monologue/application"
end

#updateObject



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

def update
  if @post.update(post_params)
    prepare_flash_and_redirect_to_edit()
  else
    render :edit
  end
end