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