Class: SimpleDiscussion::ForumThreadsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/simple_discussion/forum_threads_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#is_moderator?, #is_moderator_or_owner?, #page_number, #require_mod_or_author_for_post!, #require_mod_or_author_for_thread!

Instance Method Details

#answeredObject



10
11
12
13
# File 'app/controllers/simple_discussion/forum_threads_controller.rb', line 10

def answered
  @forum_threads = ForumThread.solved.sorted.includes(:user, :forum_category).paginate(page: page_number)
  render action: :index
end

#createObject



40
41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/simple_discussion/forum_threads_controller.rb', line 40

def create
  @forum_thread = current_user.forum_threads.new(forum_thread_params)
  @forum_thread.forum_posts.each { |post| post.user_id = current_user.id }

  if @forum_thread.save
    SimpleDiscussion::ForumThreadNotificationJob.perform_later(@forum_thread)
    redirect_to simple_discussion.forum_thread_path(@forum_thread)
  else
    render action: :new
  end
end

#editObject



52
53
# File 'app/controllers/simple_discussion/forum_threads_controller.rb', line 52

def edit
end

#indexObject



6
7
8
# File 'app/controllers/simple_discussion/forum_threads_controller.rb', line 6

def index
  @forum_threads = ForumThread.pinned_first.sorted.includes(:user, :forum_category).paginate(page: page_number)
end

#mineObject



20
21
22
23
# File 'app/controllers/simple_discussion/forum_threads_controller.rb', line 20

def mine
  @forum_threads = ForumThread.where(user: current_user).sorted.includes(:user, :forum_category).paginate(page: page_number)
  render action: :index
end

#newObject



35
36
37
38
# File 'app/controllers/simple_discussion/forum_threads_controller.rb', line 35

def new
  @forum_thread = ForumThread.new
  @forum_thread.forum_posts.new
end

#participatingObject



25
26
27
28
# File 'app/controllers/simple_discussion/forum_threads_controller.rb', line 25

def participating
  @forum_threads = ForumThread.includes(:user, :forum_category).joins(:forum_posts).where(forum_posts: {user_id: current_user.id}).distinct(forum_posts: :id).sorted.paginate(page: page_number)
  render action: :index
end

#showObject



30
31
32
33
# File 'app/controllers/simple_discussion/forum_threads_controller.rb', line 30

def show
  @forum_post = ForumPost.new
  @forum_post.user = current_user
end

#unansweredObject



15
16
17
18
# File 'app/controllers/simple_discussion/forum_threads_controller.rb', line 15

def unanswered
  @forum_threads = ForumThread.unsolved.sorted.includes(:user, :forum_category).paginate(page: page_number)
  render action: :index
end

#updateObject



55
56
57
58
59
60
61
# File 'app/controllers/simple_discussion/forum_threads_controller.rb', line 55

def update
  if @forum_thread.update(forum_thread_params)
    redirect_to simple_discussion.forum_thread_path(@forum_thread), notice: I18n.t("your_changes_were_saved")
  else
    render action: :edit
  end
end