Strong parameters require multiple

前端 未结 7 1616
广开言路
广开言路 2020-12-30 19:03

I\'m receiving a JSON package like:

{
  \"point_code\" : { \"guid\" : \"f6a0805a-3404-403c-8af3-bfddf9d334f2\" }
}

I would like to tell Rai

7条回答
  •  礼貌的吻别
    2020-12-30 19:52

    Although a lot of these answers show you how to get what you're asking for, I would like to add to these answers and suggest that you use a before_action. If the required params are missing, require will automatically return a 400 error

    class SomeController < ApplicationController
      before_action :ensure_valid_params, only: :index
    
      def index
        # do your stuff
      end
    
    private
    
      def ensure_valid_params
        params.require(:some_required_param)
      end
    end
    

提交回复
热议问题