Class: HelpCenter::SupportThreadsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/help_center/support_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/help_center/support_threads_controller.rb', line 10

def answered
  @support_threads = SupportThread.solved.sorted.includes(:user, :support_category).paginate(page: page_number)
  render action: :index
end

#createObject



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

def create
  @support_thread = current_user.support_threads.new(support_thread_params)
  @support_thread.support_posts.each{ |post| post.user_id = current_user.id }

  if @support_thread.save
    HelpCenter::SupportThreadNotificationJob.perform_later(@support_thread)
    redirect_to help_center.support_thread_path(@support_thread)
  else
    render action: :new
  end
end

#editObject



52
53
# File 'app/controllers/help_center/support_threads_controller.rb', line 52

def edit
end

#indexObject



6
7
8
# File 'app/controllers/help_center/support_threads_controller.rb', line 6

def index
  @support_threads = SupportThread.pinned_first.sorted.includes(:user, :support_category).paginate(page: page_number)
end

#mineObject



20
21
22
23
# File 'app/controllers/help_center/support_threads_controller.rb', line 20

def mine
  @support_threads = SupportThread.where(user: current_user).sorted.includes(:user, :support_category).paginate(page: page_number)
  render action: :index
end

#newObject



35
36
37
38
# File 'app/controllers/help_center/support_threads_controller.rb', line 35

def new
  @support_thread = SupportThread.new
  @support_thread.support_posts.new
end

#participatingObject



25
26
27
28
# File 'app/controllers/help_center/support_threads_controller.rb', line 25

def participating
  @support_threads = SupportThread.includes(:user, :support_category).joins(:support_posts).where(support_posts: { user_id: current_user.id }).distinct(support_posts: :id).sorted.paginate(page: page_number)
  render action: :index
end

#showObject



30
31
32
33
# File 'app/controllers/help_center/support_threads_controller.rb', line 30

def show
  @support_post = SupportPost.new
  @support_post.user = current_user
end

#unansweredObject



15
16
17
18
# File 'app/controllers/help_center/support_threads_controller.rb', line 15

def unanswered
  @support_threads = SupportThread.unsolved.sorted.includes(:user, :support_category).paginate(page: page_number)
  render action: :index
end

#updateObject



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

def update
  if @support_thread.update(support_thread_params)
    redirect_to help_center.support_thread_path(@support_thread), notice: I18n.t('your_changes_were_saved')
  else
    render action: :edit
  end
end