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
14
# File 'app/controllers/help_center/support_threads_controller.rb', line 10

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

#createObject



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

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



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

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

#editObject



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

def edit
end

#indexObject



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

def index
  redirect_to help_center.support_categories_path
end

#mineObject



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

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

#newObject



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

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

#participatingObject



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

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



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

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

#unansweredObject



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

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

#updateObject



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

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