When JSON data posted in rails throws param is missing or the value is empty: stall -


i have been trying post json data via postman "param missing or value empty: stall". can please tell me i'm going wrong?

 def create    @stall = stall.new(stall_params)         if @stall.save          render json: @stall, status: :created        else            render json: @stall.errors, status: :unprocessable_entity     end   end    private def stall_params   params.require(:stall).permit(:name, :place) end 

my table contains 2 columns name , place

below log

processing api::v1::stallscontroller#create json   parameters: {"name"=>"trill", "place"=>"trill"} completed 400 bad request in 0ms (activerecord: 0.0ms)  actioncontroller::parametermissing (param missing or value empty: stall):   app/controllers/api/v1/stalls_controller.rb:47:in `stall_params'   app/controllers/api/v1/stalls_controller.rb:27:in `create'     rendered /home/goutham/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/rescues/_source.erb (7.4ms)   rendered /home/goutham/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (16.0ms)   rendered /home/goutham/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (0.9ms)   rendered /home/goutham/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (135.0ms) 

your stall_params method searches params in 'stall' namespace.

your json parameters must have following format:

'stall': {   'name': 'trill',   'place': 'trill' } 

if want parameters in top namespace, have remove #require call in stall_params.

params.permit(:name, :place) 

Comments