testy/app/controllers/chains_controller.rb
Mohammad Kanaan 2cc3c1a7dd
Some checks are pending
CI / scan_ruby (push) Waiting to run
CI / lint (push) Waiting to run
CI / test (push) Waiting to run
initial commit
2026-05-17 14:12:43 +03:00

51 lines
1,023 B
Ruby

class ChainsController < ApplicationController
before_action :set_chain, only: %i[ show update destroy ]
# GET /chains
def index
@chains = Chain.all
render json: @chains
end
# GET /chains/1
def show
render json: @chain
end
# POST /chains
def create
@chain = Chain.new(chain_params)
if @chain.save
render json: @chain, status: :created, location: @chain
else
render json: @chain.errors, status: :unprocessable_content
end
end
# PATCH/PUT /chains/1
def update
if @chain.update(chain_params)
render json: @chain
else
render json: @chain.errors, status: :unprocessable_content
end
end
# DELETE /chains/1
def destroy
@chain.destroy!
end
private
# Use callbacks to share common setup or constraints between actions.
def set_chain
@chain = Chain.find(params.expect(:id))
end
# Only allow a list of trusted parameters through.
def chain_params
params.expect(chain: [ :name ])
end
end