score:1

Accepted answer

As we discussed in the comments, the CustomersController actually ends after the create method, so the update, destroy, customer_params, and set_customer methods all fall outside of the CustomersController. So, moving the third end after the create method to end of the file should fix it. Your controller should look like:

class CustomersController < ApplicationController
  before_action :set_customer, only: [:update, :destroy]

  def index
    @customers = Customer.all
  end

  def create
    @customer = Customer.new(customer_params)

    if @customer.save
      render json: @customer
    else
      render json: @customer.errors, status: :unprocessable_entity
    end
  end
# note that there was a third end here

  def update
    if @customer.update(customer_params)
      render json: @customer
    else
      render json: @customer.errors, status: :unprocessable_entity
    end
  end

  def destroy
    @customer.destroy
    head :no_content
  end

  private

  def customer_params
    params.require(:customer).permit(:name, :lastname, :mobile, :phone, :email, :address, :zip, :city, :state)
  end

  def set_customer
    @customer = Customer.find(params[:id])
  end
end # end moved to here

Related Query

More Query from same tag