docbrown/app/controllers/html_variants_controller.rb
Keshav Biswa 8d57d45ecc Rubocop Style cops enabled (#2056)
* Rubocop enabled style/alias

* Enabled Style/ArrayJoin Cop

* Enabled Style/Attr

* Enabled Case Equality

* Enabled CharacterLiteral

*  Enabled ColonMethodCall Cop

* Enabled CommentAnnotation cop

* Enabled PreferredHashMethods Cop

*  Enabled DoubleNegation Cop

* Enabled EachWithObject Cop

* Enabled EmptyLiteral Cop

* Enabled EvenOdd Cop

* Enabled IfWithSemicolon Cop

* Enabled Lambda and LambdaCall Cop

* Enabled LineEndConcatenation Cop

* Enabled ModuleFunction Cop;

* Enable NegatedIf and NegatedWhile Cop

* Enabled NilComparison Cop

* Enabled Not Cop

* Enabled NumericLiterals Cop

* Enabled OneLineConditional Cop

* Enabled PercentLiteralDelimiters Cop

* Excluded internal/users_controller from negated_if cop

* Reverted the double negation change from github_issue_tag and github_issue.rb"

* Enabled PerlBackrefs Cop

* Changed Regexp.last_match(1) to Regexp.last_match(0)

* Enabled proc cop

* Enabled RaiseArgs Cop

* Reverted Regexp.last_match(0) to Regexp.last_match(1)

* Enabled SelfAssignment Cop

* Enabled SingleLineMethods Cop

* Enabled SpecialGlobalVars Cop

* Enabled VariableInterpolation Cop

* Enabled WhenThen Cop

* Enabled WhileUntilModifier Cop

* Enabled WordArray Cop

* Enabled IfUnlessModifier Cop

* Enabled GuardClause Cop
2019-03-15 18:33:54 -04:00

66 lines
1.9 KiB
Ruby

class HtmlVariantsController < ApplicationController
after_action :verify_authorized
def index
authorize HtmlVariant
@html_variants = if params[:state] == "mine"
current_user.html_variants.order("created_at DESC").includes(:user).page(params[:page]).per(15)
elsif params[:state] == "admin"
HtmlVariant.where(published: true, approved: false).order("created_at DESC").includes(:user).page(params[:page]).per(15)
else
HtmlVariant.where(published: true, approved: true).order("success_rate DESC").includes(:user).page(params[:page]).per(15)
end
end
def new
authorize HtmlVariant
@html_variant = HtmlVariant.new
return unless params[:fork_id]
@fork = HtmlVariant.find(params[:fork_id])
@html_variant.name = @fork.name + " FORK-#{rand(10_000)}"
@html_variant.html = @fork.html
end
def show
@story_show = true
@@article_show = true
@html_variant = HtmlVariant.find(params[:id])
authorize @html_variant
render layout: false
end
def edit
@html_variant = HtmlVariant.find(params[:id])
authorize @html_variant
end
def create
authorize HtmlVariant
@html_variant = HtmlVariant.new(html_variant_params)
@html_variant.user_id = current_user.id
if @html_variant.save
flash[:success] = "HTML Variant Created"
redirect_to "/html_variants/#{@html_variant.id}/edit"
else
render :new
end
end
def update
@html_variant = HtmlVariant.find(params[:id])
authorize @html_variant
if @html_variant.update(html_variant_params)
flash[:success] = "HTML Variant Updated"
redirect_to "/html_variants/#{@html_variant.id}/edit"
else
render :edit
end
end
private
def html_variant_params
params.require(:html_variant).permit(policy(HtmlVariant).permitted_attributes)
end
end