Module: Controllers::Articlable

Extended by:
ActiveSupport::Concern
Included in:
ArticleFaqsController, ArticleProceduresController, ArticleTechnicalsController, ArticleTrainingsController, Crm::PostCommentsController, Crm::PostsController
Defined in:
app/concerns/controllers/articlable.rb

Overview

ActiveSupport::Concern mixin: articlable.

Instance Method Summary collapse

Instance Method Details

#convert_typevoid

This method returns an undefined value.



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'app/concerns/controllers/articlable.rb', line 63

def convert_type
  load_article
  authorize!(:update, @article)
  new_type = params.expect(:article_type_id).to_s

  unless Article::STI_TYPES.key?(new_type)
    flash[:error] = 'Invalid article type for conversion.'
    redirect_to polymorphic_path(@article) and return
  end

  previous_embedding_type = @article.embedding_type_name
  converted = Article.transaction do
    @article.update_columns(type: new_type, state: 'draft')
    current = Article.find(@article.id)
    Article.delete_content_embeddings_for(
      current.id,
      embedding_types: [previous_embedding_type, current.embedding_type_name]
    )
    current
  end
  flash[:info] = 'Article has been converted and changed to Draft state.'
  redirect_to polymorphic_path([:edit, converted])
rescue ActionController::UrlGenerationError, NoMethodError
  flash[:error] = 'Article converted but could not resolve edit path.'
  redirect_to articles_path
end

#destroyvoid

This method returns an undefined value.



53
54
55
56
57
58
59
60
# File 'app/concerns/controllers/articlable.rb', line 53

def destroy
  controller = controller_name
  load_article
  @article.destroy
  respond_to do |format|
    format.html { redirect_to_return_path_or_default send("#{controller}_path") }
  end
end

#editvoid

This method returns an undefined value.



47
48
49
50
# File 'app/concerns/controllers/articlable.rb', line 47

def edit
  load_article
  authorize!(:update, @article)
end

#indexvoid

This method returns an undefined value.



10
11
12
13
14
15
16
# File 'app/concerns/controllers/articlable.rb', line 10

def index
  authorize!(:read, Article)
  klass = model_class
  @q = klass.ransack(params[:q])
  @q.sorts = 'created_at DESC' if @q.sorts.blank?
  @pagy, @articles = pagy(@q.result.includes(:product_lines, taggings: :tag).order(created_at: :desc))
end

#load_articlevoid (protected)

This method returns an undefined value.



93
94
95
# File 'app/concerns/controllers/articlable.rb', line 93

def load_article
  @article = model_class.friendly.find(params[:id])
end

#showvoid

This method returns an undefined value.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/concerns/controllers/articlable.rb', line 19

def show
  load_article
  respond_to do |format|
    format.html
    format.pdf do
      result = Pdf::Document::Article.call(@article)
      send_data result.pdf, filename: result.file_name, type: 'application/pdf', disposition: 'inline'
    rescue Pdf::Document::Article::GenerationError => e
      Rails.logger.error("[Articlable#show] PDF generation failed for article #{@article.id}: #{e.message}")
      flash[:error] = 'PDF generation is temporarily unavailable. Please try again later.'
      redirect_to polymorphic_path(@article)
    end
  end
end

#show_descriptionvoid

This method returns an undefined value.



35
36
37
38
# File 'app/concerns/controllers/articlable.rb', line 35

def show_description
  load_article
  render layout: 'www/cms_page'
end

#show_solutionvoid

This method returns an undefined value.



41
42
43
44
# File 'app/concerns/controllers/articlable.rb', line 41

def show_solution
  load_article
  render layout: 'www/cms_page'
end