answers_controller.rb 912 B

1234567891011121314151617181920212223242526
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class KnowledgeBase::Public::AnswersController < KnowledgeBase::Public::BaseController
  3. def show
  4. @category = find_category(params[:category])
  5. @object = find_answer(@category&.answers, params[:answer])
  6. @object_locales = find_locales(@object)
  7. render_alternative if @object.blank?
  8. end
  9. private
  10. def render_alternative
  11. answers = @knowledge_base.answers.where(category: params[:category]).eager_load(translations: :kb_locale)
  12. @alternative = find_answer(answers, params[:answer], locale: false)
  13. raise ActiveRecord::RecordNotFound if !@alternative&.translations&.any? # rubocop:disable Style/InverseMethods
  14. @object_locales = @alternative.translations.map { |x| x.kb_locale.system_locale }
  15. render 'knowledge_base/public/show_alternatives', locals: { name: 'Answer' }
  16. end
  17. end