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, #send_private_message_path, #topic_path, #topic_url, #unread_topics_path, #user_path
Instance Method Details
#create ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'app/controllers/thredded/posts_controller.rb', line 22
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
|
#destroy ⇒ Object
49
50
51
52
53
54
55
|
# File 'app/controllers/thredded/posts_controller.rb', line 49
def destroy
authorize post, :destroy?
post.destroy!
redirect_back fallback_location: topic_url(topic),
notice: I18n.t('thredded.posts.deleted_notice')
end
|
#edit ⇒ Object
35
36
37
38
39
40
|
# File 'app/controllers/thredded/posts_controller.rb', line 35
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_read ⇒ Object
57
58
59
60
61
62
63
64
|
# File 'app/controllers/thredded/posts_controller.rb', line 57
def mark_as_read
authorize post, :read?
UserTopicReadState.touch!(thredded_current_user.id, post)
respond_to do |format|
format.html { redirect_back fallback_location: post_path(post, user: thredded_current_user) }
format.json { render(json: { read: true }) }
end
end
|
#mark_as_unread ⇒ Object
66
67
68
69
70
71
72
73
|
# File 'app/controllers/thredded/posts_controller.rb', line 66
def mark_as_unread
authorize post, :read?
post.mark_as_unread(thredded_current_user)
respond_to do |format|
format.html { after_mark_as_unread } format.json { render(json: { read: false }) }
end
end
|
#new ⇒ Object
15
16
17
18
19
20
|
# File 'app/controllers/thredded/posts_controller.rb', line 15
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
|
#update ⇒ Object
42
43
44
45
46
47
|
# File 'app/controllers/thredded/posts_controller.rb', line 42
def update
authorize post, :update?
post.update(new_post_params)
redirect_to post_path(post, user: thredded_current_user)
end
|