Class: MyForum::TopicsController
Instance Method Summary
collapse
#authenticate_user!, #current_user, #current_user_groups, #current_user_id, #forum_time, #is_admin?, #new_pm_count
Instance Method Details
#close ⇒ Object
47
48
49
50
51
52
|
# File 'app/controllers/my_forum/topics_controller.rb', line 47
def close
return unless topic = Topic.find_by_id(params[:topic_id])
topic.toggle!(:closed)
redirect_to forum_topic_path(topic.forum, topic)
end
|
#create ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'app/controllers/my_forum/topics_controller.rb', line 25
def create
raise unless current_user
topic = @forum.topics.build(topic_params)
post = topic.posts.build(post_params)
post.user = current_user
topic.save
post.save
topic.mark_as_read(current_user, post)
redirect_to forum_path(@forum)
end
|
#delete ⇒ Object
54
55
56
57
58
59
|
# File 'app/controllers/my_forum/topics_controller.rb', line 54
def delete
return unless topic = Topic.find_by_id(params[:topic_id])
topic.update!(deleted: true)
redirect_to forum_path(topic.forum)
end
|
#new ⇒ Object
8
9
10
|
# File 'app/controllers/my_forum/topics_controller.rb', line 8
def new
@topic = @forum.topics.build
end
|
#pin ⇒ Object
40
41
42
43
44
45
|
# File 'app/controllers/my_forum/topics_controller.rb', line 40
def pin
return unless topic = Topic.find_by_id(params[:topic_id])
topic.toggle!(:pinned)
redirect_to forum_topic_path(topic.forum, topic)
end
|
#show ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'app/controllers/my_forum/topics_controller.rb', line 12
def show
@topic = Topic.find(params[:id])
check_access_permissions(@topic)
user_last_page = get_last_readed_user_page
@topic_posts = @topic.posts.includes(:user, :topic).paginate(per_page: Post::PER_PAGE, page: (params[:page] || user_last_page))
@new_post = Post.new
@topic.mark_as_read(current_user, @topic_posts.last)
@topic.increment!(:views) if current_user
end
|