Class: MyForum::TopicsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/my_forum/topics_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#authenticate_user!, #current_user, #current_user_groups, #current_user_id, #forum_time, #is_admin?, #new_pm_count

Instance Method Details

#closeObject



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

#createObject



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
  #TODO !
  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

#deleteObject



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

#newObject



8
9
10
# File 'app/controllers/my_forum/topics_controller.rb', line 8

def new
  @topic = @forum.topics.build
end

#pinObject



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

#showObject



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 #TODO if quick_answer_enabled

  @topic.mark_as_read(current_user, @topic_posts.last)
  @topic.increment!(:views) if current_user
end