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



11
12
13
14
15
# File 'app/controllers/help_center/support_threads_controller.rb', line 11

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

#createObject



45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/help_center/support_threads_controller.rb', line 45

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

#destroyObject



68
69
70
71
# File 'app/controllers/help_center/support_threads_controller.rb', line 68

def destroy
  @support_thread.destroy
  redirect_to help_center.support_category_path(@support_thread.support_category), notice: I18n.t('successfully_deleted')
end

#editObject



57
58
# File 'app/controllers/help_center/support_threads_controller.rb', line 57

def edit
end

#indexObject



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

def index
  @support_threads = SupportThread.pinned_first.sorted.includes(:user, :support_category)
  @pagy, @records = pagy(@support_threads)
end

#mineObject



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

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

#newObject



40
41
42
43
# File 'app/controllers/help_center/support_threads_controller.rb', line 40

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

#participatingObject



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

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
  @pagy, @records = pagy(@support_threads)
  render action: :index
end

#showObject



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

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

#unansweredObject



17
18
19
20
21
# File 'app/controllers/help_center/support_threads_controller.rb', line 17

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

#updateObject



60
61
62
63
64
65
66
# File 'app/controllers/help_center/support_threads_controller.rb', line 60

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