Class: Public::ArticlesController

Inherits:
Postnhost::PublicController
  • Object
show all
Includes:
Postnhost::CanonicalFirstPageRedirect, Postnhost::LanguageSwitcher, Postnhost::PublicFooterData, Postnhost::PublicHttpCaching, Postnhost::PublicPageSize, Postnhost::PublicTemplateResolvable
Defined in:
app/controllers/postnhost/public/articles_controller.rb

Constant Summary collapse

TOP_PICKS_LIMIT =
4

Constants included from Postnhost::PublicPageSize

Postnhost::PublicPageSize::PAGINATION_SLOTS

Instance Method Summary collapse

Methods included from Postnhost::PublicTemplateResolvable

#default_url_options

Instance Method Details

#indexObject



18
19
20
21
22
23
24
25
# File 'app/controllers/postnhost/public/articles_controller.rb', line 18

def index
  apply_public_http_cache(params[:page].to_i, template: resolve_public_template("articles/index"))
  return if performed?

  set_footer_data
  load_index_collection
  render_public_template("articles/index")
end

#previewObject



65
66
67
68
69
70
71
72
73
74
75
# File 'app/controllers/postnhost/public/articles_controller.rb', line 65

def preview
  set_footer_data
  @article = Postnhost::Article.includes(:categories, :language, article_authors: :user).find(params[:id])

  @content = @article
  @actual_language = @article.language || @current_language

  @available_variants = @article.article_variants.includes(:language)

  render_public_template("articles/preview")
end

#searchObject



27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/postnhost/public/articles_controller.rb', line 27

def search
  @search_query = normalized_search_query
  apply_public_http_cache(@search_query, params[:page].to_i, template: resolve_public_template("articles/index"))
  return if performed?

  set_footer_data
  load_index_collection(search_only: true)

  render_public_template("articles/index")
end

#showObject

Raises:

  • (ActiveRecord::RecordNotFound)


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/controllers/postnhost/public/articles_controller.rb', line 38

def show
  resolution = public_route_resolution(kind: :article, slug: params[:slug])
  apply_public_http_cache(resolution.record_id, template: resolve_public_template("articles/show"))
  return if performed?

  @article = resolution.record
  raise ActiveRecord::RecordNotFound if !localized_request? && @article.language_id != @current_language.id

  preload_article_associations

  if localized_request?
    @article_variant = @article.article_variant_snapshots.for_language(@current_language).first!
    @content = @article_variant
    @actual_language = @article_variant.language
    @primary_language = @article.language
  else
    @content = @article
    @actual_language = @current_language
    @primary_language = @current_language
  end

  @available_variants = @article.article_variant_snapshots.with_language.to_a

  set_footer_data
  render_public_template("articles/show")
end