Class: Thredded::PostsController

Inherits:
ApplicationController show all
Includes:
ActionView::RecordIdentifier, NewPostParams
Defined in:
app/controllers/thredded/posts_controller.rb

Overview

A controller for managing Posts.

Instance Method Summary collapse

Methods included from UrlsHelper

#delete_post_path, #edit_post_path, #edit_preferences_path, #edit_preferences_url, #mark_unread_path, #permalink_path, #post_path, #post_url, #quote_post_path, #search_path, #topic_path, #topic_url, #user_path

Instance Method Details

#createObject



21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/thredded/posts_controller.rb', line 21

def create
  @post_form = Thredded::PostForm.new(
    user: thredded_current_user, topic: parent_topic, post_params: new_post_params
  )
  authorize_creating @post_form.post

  if @post_form.save
    redirect_to post_path(@post_form.post, user: thredded_current_user)
  else
    render :new
  end
end

#destroyObject



48
49
50
51
52
53
54
# File 'app/controllers/thredded/posts_controller.rb', line 48

def destroy
  authorize post, :destroy?
  post.destroy!

  redirect_back fallback_location: topic_url(topic),
                notice: I18n.t('thredded.posts.deleted_notice')
end

#editObject



34
35
36
37
38
39
# File 'app/controllers/thredded/posts_controller.rb', line 34

def edit
  @post_form = Thredded::PostForm.for_persisted(post)
  authorize @post_form.post, :update?
  return redirect_to(canonical_topic_params) unless params_match?(canonical_topic_params)
  render
end

#mark_as_unreadObject



56
57
58
59
60
61
# File 'app/controllers/thredded/posts_controller.rb', line 56

def mark_as_unread
  authorize post, :read?
  page = post.page(user: thredded_current_user)
  post.mark_as_unread(thredded_current_user, page)
  after_mark_as_unread # customization hook
end

#newObject



14
15
16
17
18
19
# File 'app/controllers/thredded/posts_controller.rb', line 14

def new
  @post_form = Thredded::PostForm.new(
    user: thredded_current_user, topic: parent_topic, post_params: new_post_params
  )
  authorize_creating @post_form.post
end

#quoteObject



63
64
65
66
# File 'app/controllers/thredded/posts_controller.rb', line 63

def quote
  authorize_reading post
  render plain: Thredded::ContentFormatter.quote_content(post.content)
end

#updateObject



41
42
43
44
45
46
# File 'app/controllers/thredded/posts_controller.rb', line 41

def update
  authorize post, :update?
  post.update(new_post_params)

  redirect_to post_path(post, user: thredded_current_user)
end