docbrown/app/controllers/blocks_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

80 lines
1.9 KiB
Ruby

class BlocksController < ApplicationController
before_action :set_block, only: %i[show edit update destroy]
after_action :verify_authorized
# GET /blocks
# GET /blocks.json
def index
authorize Block
@blocks = Block.order("index_position ASC")
end
# GET /blocks/1
# GET /blocks/1.json
def show
authorize @block
end
# GET /blocks/new
def new
authorize Block
@block = Block.new
end
# GET /blocks/1/edit
def edit
authorize @block
end
# POST /blocks
# POST /blocks.json
def create
authorize Block
@block = Block.new(permitted_attributes(Block))
@block.user_id = current_user.id
respond_to do |format|
if @block.save
format.html { redirect_to @block, notice: "Block was successfully created." }
format.json { render :show, status: :created, location: @block }
else
format.html { render :new }
format.json { render json: @block.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /blocks/1
# PATCH/PUT /blocks/1.json
def update
authorize @block
respond_to do |format|
if @block.update(permitted_attributes(@block))
@block.publish! if permitted_attributes(@block)[:publish_now]
format.html { redirect_to @block, notice: "Block was successfully updated." }
format.json { render :show, status: :ok, location: @block }
else
format.html { render :edit }
format.json { render json: @block.errors, status: :unprocessable_entity }
end
end
end
# DELETE /blocks/1
# DELETE /blocks/1.json
def destroy
authorize @block
@block.destroy
respond_to do |format|
format.html { redirect_to blocks_url, notice: "Block was successfully destroyed." }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_block
@block = Block.find(params[:id])
end
end