Class: Thredded::PostsController

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

Instance Method Summary collapse

Methods included from UrlsHelper

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

Instance Method Details

#createObject



11
12
13
14
15
16
17
# File 'app/controllers/thredded/posts_controller.rb', line 11

def create
  post = parent_topic.posts.build(post_params)
  authorize_creating post
  post.save!

  redirect_to post_path(post, user: thredded_current_user)
end

#destroyObject



30
31
32
33
34
35
36
# File 'app/controllers/thredded/posts_controller.rb', line 30

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

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

#editObject



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

def edit
  authorize post, :update?
end

#updateObject



23
24
25
26
27
28
# File 'app/controllers/thredded/posts_controller.rb', line 23

def update
  authorize post, :update?
  post.update_attributes(post_params.except(:user, :ip))

  redirect_to post_path(post, user: thredded_current_user)
end