编程时我遇到了以下错误。
#NoMethodError: undefined method `inventories' for #<Person:0x35e1538>
当我发送帖子以插入
时,他会出现此错误下面的代码
def create
@person = Person.create(person_params)
if @person.save
render json: @person, status: :created, location: @persons
else
render json: @person.errors, status: :unprocessable_entity
end
end
def person_params
params.require(:person).permit(:name, :age, :gender, :lonlat, :infected)
end
角
$scope.SendData = function (people) {
var data = {
"person" : {
"name": people.name,
"age": people.age,
"gender": people.gender,
"lonlat": people.lonlat,
"infected": people.infected
}
};
$http({
method: 'POST',
url: 'http://localhost:3000/people',
headers: {'Content-Type': 'application/json'},
data: data
}).then(function(response) {
location.reload();
}).catch(function(err){
console.log(err)
});
};