Class: MyForum::PostsController
Instance Method Summary
collapse
#bbquote, #format_bbcode, #format_post_text
#authenticate_user!, #current_user, #current_user_groups, #current_user_id, #forum_time, #is_admin?, #new_pm_count
Instance Method Details
#create ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'app/controllers/my_forum/posts_controller.rb', line 11
def create
unless params[:post].fetch(:text).blank?
post = @topic.posts.build(post_params)
post.user = current_user
post.save
process_attachments(post)
end
last_page = (@topic.posts.count.to_f / Post::PER_PAGE).ceil
last_page = 1 if last_page == 0
ping_user params[:post].fetch(:text), last_page
redirect_to forum_topic_path(@forum, @topic, page: last_page, go_to_last_post: true)
end
|
#destroy ⇒ Object
28
29
30
31
32
|
# File 'app/controllers/my_forum/posts_controller.rb', line 28
def destroy
post = Post.find(params[:id])
post.update(is_deleted: true)
redirect_to forum_topic_path(post.topic.forum, post.topic)
end
|
#edit ⇒ Object
41
42
43
44
45
|
# File 'app/controllers/my_forum/posts_controller.rb', line 41
def edit
@forum = Forum.find(params[:forum_id])
@topic = Topic.find(params[:topic_id])
@post = Post.find(params[:id])
end
|
#preview ⇒ Object
56
57
58
59
|
# File 'app/controllers/my_forum/posts_controller.rb', line 56
def preview
preview_html = ActionController::Base.helpers.sanitize format_bbcode(params[:text])
render '/my_forum/shared/post_preview.js.coffee', layout: false, locals: { preview_html: preview_html }
end
|
#show ⇒ Object
34
35
36
37
38
39
|
# File 'app/controllers/my_forum/posts_controller.rb', line 34
def show
post = Post.find(params[:id])
respond_to do |format|
format.js { render json: { text: post.text, author: post.user.login }.as_json, status: :ok }
end
end
|
#update ⇒ Object
47
48
49
50
51
52
53
54
|
# File 'app/controllers/my_forum/posts_controller.rb', line 47
def update
post = Post.find(params[:id])
post.text = params[:post][:text]
post.edited_by = current_user.login
post.save
redirect_to forum_topic_path(post.topic.forum, post.topic, page: params[:page])
end
|