I am trying to make a post using Postman on my Rails app and I get an issue saying:
ActionController::ParameterMissing (param is missing or the value is empty: vendor
Did you mean? vendor_data
action
quote_type
controller):
This is my controller
file where the params are called:
def create_vendor_params
params.require(:vendor).permit(
:vendor_id, :quote_type, :first_name, :last_name, :email, :phone_type, :phone, :request_type, :address1, :address_city, :address_state, :address_zip, :DOB
)
end
And this is the data I am sending from Postman. Now I am not sure if it's because renter_data
it's nested and on my params permit
:
{
"vendor_id": 2,
"quote_type": "renter",
"renter_data": {
"first_name":"Tony",
"last_name":"Stark",
"email":"tony@starkindustries",
"phone_type":"mobile",
"phone":"6504881234",
"request_type":"renter",
"address1":"123 Main Street",
"address_city":"Palo Alto",
"address_state":"CA",
"address_zip":"94301",
"DOB":"1990-07-22"
}
}
Is this issue because of nested data inside renter_data
? And if it is, how can I nest it?
EDIT
When I make the post I see an empty object at the end of the request:
Processing by Api::V2::LeadController#create as */*
Parameters: {"vendor_id"=>2, "quote_type"=>"renter", "renter_data"=>{"first_name"=>"Tony", "last_name"=>"Stark", "email"=>"tony@starkindustries", "phone_type"=>"mobile", "phone"=>"6504881234", "request_type"=>"renter", "address1"=>"123 Main Street", "address_city"=>"Palo Alto", "address_state"=>"CA", "address_zip"=>"94301", "DOB"=>"1990-07-22"}, "vendor"=>{} <---HERE }
Why is that?
CodePudding user response:
This is the concept of nested strong params in create_vender_params function you have to add more permitted params
params.require(:vendor).permit(
:vendor_id, :quote_type, renter_Data: [:first_name, :last_name, :email, :phone_type, :phone, :request_type, :address1, :address_city, :address_state, :address_zip, :DOB])
CodePudding user response:
There are two problems: First, the strong params expect the input to be nested under vendor
. Second, the strong params do not expect a nested renter_data
hash.
To fix this in your query change the structure of the request data to:
{
"vendor": {
"vendor_id": 2,
"quote_type": "renter",
"first_name":"Tony",
"last_name":"Stark",
"email":"tony@starkindustries",
"phone_type":"mobile",
"phone":"6504881234",
"request_type":"renter",
"address1":"123 Main Street",
"address_city":"Palo Alto",
"address_state":"CA",
"address_zip":"94301",
"DOB":"1990-07-22"
}
}
If you want to keep the nested renter_data
hash then you have to change the strong params like Paarth Agrawal already suggested. But then you still need to nest everything under vendor
.