I keep getting this message #<ActionController::ParameterMissing: param is missing or the value is empty: property>, and just don't know how to resolve depsite all the research I have done and compared my work to.
I think I have my create action setup properly
def create
raise params.inspect
@property = Property.create(prop_params)
if @property.save!
render json: @property
else
render json: { error: "Couldn't save"}
end
end
def prop_params
params.require(:property).permit(:address, :state, :sale_price, :owner_id)
end
Here is my model as well for properties.
class Property < ApplicationRecord
belongs_to :owner
end
When I do a raise param.inspect I get this
Object { status: 500, error: "Internal Server Error", exception: "#<RuntimeError: <ActionController::Parameters {\"controller\"=>\"properties\", \"action\"=>\"create\"} permitted: false>>", traces: {…} }
I know its supposed to show what I passed but at some point it just stop showing what I passed in and just started showing controller and the action.
How am I submitting the form on the frontend?
listForm.addEventListener('submit',(event) =>{
event.preventDefault();
const property = {
address: document.getElementById('address').value,
state: document.getElementById('state').value,
sale_price: document.getElementById('sale_price').value,
owner_id: document.getElementById('owner_id').value,
}
const listObj = {
method: 'POST',
header: {
'Content-Type': 'application/json',
"Accept": "application/json"
},
body: JSON.stringify(property)
}
fetch(PROPERTIES_URL, listObj)
.then(res => res.json())
.then((list_data) => {
let new_listing = renderListing(list_data)
listings.append(new_listing)
listForm.reset()
console.log(list_data)
})
})
How can I clear this hurdle over my strong params issue?