class CafsController < ApplicationController before_action :set_caf, only: %i[ show edit update destroy ] before_action :set_company # GET /cafs or /cafs.json def index @cafs = Caf.all end # GET /cafs/1 or /cafs/1.json def show end # GET /cafs/new def new @caf = Caf.new end # GET /cafs/1/edit def edit end # POST /cafs or /cafs.json def create @caf = Caf.new(caf_params) respond_to do |format| if @caf.save format.html { redirect_to company_caf_url(@caf.company_id,@caf.id), notice: "Caf was successfully created." } format.json { render :show, status: :created, location: @caf } else format.html { render :new, status: :unprocessable_entity } format.json { render json: @caf.errors, status: :unprocessable_entity } end end end # PATCH/PUT /cafs/1 or /cafs/1.json def update respond_to do |format| if @caf.update(caf_params) format.html { redirect_to caf_url(@caf), notice: "Caf was successfully updated." } format.json { render :show, status: :ok, location: @caf } else format.html { render :edit, status: :unprocessable_entity } format.json { render json: @caf.errors, status: :unprocessable_entity } end end end # DELETE /cafs/1 or /cafs/1.json def destroy @caf.destroy respond_to do |format| format.html { redirect_to cafs_url, notice: "Caf was successfully destroyed." } format.json { head :no_content } end end private # Use callbacks to share common setup or constraints between actions. def set_caf @caf = Caf.find(params[:id]) end def set_company @company = Company.find(params[:company_id]) end # Only allow a list of trusted parameters through. def caf_params params.require(:caf).permit(:company_id, :name, :description) end end