Strong parameters require multiple

前端 未结 7 1659
广开言路
广开言路 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 20:01

    require takes one parameter. So there is no way you can pass in multiple keys unless you override the require method. You can achieve what you want with some additional logic in your action:

    def action
      raise ActionController::ParameterMissing.new("param not found: point_code") if point_params[:point_code].blank?
      raise ActionController::ParameterMissing.new("param not found: guid") if point_params[:point_code][:guid].blank?
    
      
    end
    
    def point_params
      params.permit(point_code: :guid)
    end
    

提交回复
热议问题