docbrown/app/controllers/additional_content_boxes_controller.rb
rhymes 6553f08d94 Rubocop cleanups (#1415)
* Update rubocop-todo.yml with new violations

* Fix Layout/EmptyLine* rules

* Fix Layout/Indentation* rules

* Fix remaining Layout/* rules

* Fix Lint/DuplicateMethods by removing unused accessor

* Fix Lint/IneffectiveAccessModifier

* Fix Lint/MissingCopEnableDirective

* Re-run rubocop auto gen config

* Fix Layout/RescueEnsureAlignment

* Fix Naming/* rules

* Fix some RSpec/* rules

* Fix typos

* Fix RSpec/LetBeforeExamples

* Series should only be an attr_writer, not an attr_accessor

* Fix RSpec/InstanceVariable

* Fix RSpec/InstanceVariable

* Fix RSpec/RepeatedDescription and RSpec/RepeatedExample

* Fix Style/ClassAndModuleChildren

* Fix Style/ConditionalAssignment

* Fix some Style/* rules

* Trigger Travis CI build because failing tests are not failing locally

* Revert "Fix Style/ClassAndModuleChildren"

This reverts commit 1686801d8a1516ba1894f79e24401a20dea65f99.
2019-01-02 11:20:02 -05:00

32 lines
1.1 KiB
Ruby

class AdditionalContentBoxesController < ApplicationController
# No authorization required for entirely public controller
before_action :set_cache_control_headers, only: [:index], unless: -> { current_user }
def index
article_ids = params[:article_id].split(",")
@article = Article.find(article_ids[0])
@for_user_article = Suggester::Articles::Classic.
new(current_user || @article, not_ids: article_ids).get
if (!user_signed_in? || current_user&.display_sponsors) &&
@article.user.permit_adjacent_sponsors &&
randomize
@boosted_article = Suggester::Articles::Boosted.new(
current_user,
@article,
not_ids: (article_ids + [@for_user_article&.id]), area: "additional_articles",
).suggest
else
@alt_classic = Suggester::Articles::Classic.
new(@article, not_ids: (article_ids + [@for_user_article&.id])).get
end
set_surrogate_key_header "additional_content_boxes_" + params.to_s unless current_user
render "boxes", layout: false
end
def randomize
return true unless Rails.env.production?
rand(2) == 1
end
end