NoMethodError:创建rails时的未定义方法

时间:2017-01-10 09:26:59

标签: ruby-on-rails angularjs

编程时我遇到了以下错误。

#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)
            });
        };

0 个答案:

没有答案