Class: Thredded::PostsController
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
#create ⇒ Object
19
20
21
22
23
24
25
26
27
28
|
# File 'app/controllers/thredded/posts_controller.rb', line 19
def create
@post_form = 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
|
#destroy ⇒ Object
44
45
46
47
48
49
50
|
# File 'app/controllers/thredded/posts_controller.rb', line 44
def destroy
authorize post, :destroy?
post.destroy!
redirect_back fallback_location: topic_url(topic),
notice: I18n.t('thredded.posts.deleted_notice')
end
|
#edit ⇒ Object
30
31
32
33
34
35
|
# File 'app/controllers/thredded/posts_controller.rb', line 30
def edit
@post_form = 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_unread ⇒ Object
52
53
54
55
56
57
|
# File 'app/controllers/thredded/posts_controller.rb', line 52
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 end
|
#new ⇒ Object
14
15
16
17
|
# File 'app/controllers/thredded/posts_controller.rb', line 14
def new
@post_form = PostForm.new(user: thredded_current_user, topic: parent_topic, post_params: new_post_params)
authorize_creating @post_form.post
end
|
#update ⇒ Object
37
38
39
40
41
42
|
# File 'app/controllers/thredded/posts_controller.rb', line 37
def update
authorize post, :update?
post.update_attributes(new_post_params)
redirect_to post_path(post, user: thredded_current_user)
end
|