2

I recently started learning ruby on rails and I have been working on a public transport rating app API. Rails 6.0.3.2 I can't seem to shake off this error, I checked other questions but nothing is working for me kindly help me out.

Here is the controller (matatu_controller.rb)

module Api
    module V1
        class  MatatusController < ApplicationController 
            # GET /api/v1/matatus
            def index
                matatus=Matatu.all 
                render json: MatatuSerializer.new(matatus).serialized_json    
            end
            
            # POST /api/v1/matatus   
            def create
                matatu=Matatu.new(matatu_params)
                if matatu.save
                    render json: MatatuSerializer.new(matatu).serialized_json
                else
                    render json: {error: matatu.errors.messages},status:422

                end
            end  
            private
            def matatu_params
                params.require(:matatu).permit(:name,:image_url)
                
            end
        end
    end
end

The error

ActionController::ParameterMissing (param is missing or the value is empty: matatu)

it occurs when I try to a test if the API endpoints are working using postman http://localhost:3000/api/v1/matatus POST

here is JSON that should be added when I hit send

{"name":"crystal-bus"}
kahuria00
  • 317
  • 1
  • 5
  • 14
  • This has nothing to do with your routes, models, seeds, etc. Your controller uses `params.require(:matatu)` and your frontend is submitting a request that doesn't have a `matatu` in it. We need to see the one thing you haven't included: Your invocation that is actually producing this error. – user229044 Jul 17 '20 at 01:42
  • @meagar I have included it now and got rid of all the extra code – kahuria00 Jul 17 '20 at 07:28

0 Answers0