Ruby on rails TypeError-没有将符号隐式转换为整数

Ruby on rails TypeError-没有将符号隐式转换为整数,ruby-on-rails,angularjs,hash,typeerror,Ruby On Rails,Angularjs,Hash,Typeerror,嗨,我正在构建一个带有rails和angular的应用程序。我一直在执行这段代码时遇到一个类型错误 $scope.makeTip = function(tip){ data = { tip: { bookies: tip.bookies, user_id: $scope.currentUser.id }, prediction: $scope.madePredictions }, $http.pos

嗨,我正在构建一个带有rails和angular的应用程序。我一直在执行这段代码时遇到一个类型错误

$scope.makeTip = function(tip){
    data = {
      tip: { 
        bookies: tip.bookies, 
        user_id: $scope.currentUser.id
      }, 
      prediction: $scope.madePredictions
    },
    $http.post('/tips.json', data).success(function(data){
      console.log(data)
    });
  };
  $http.get('/predictions/fixtures_this_week').success(function(response){
    $scope.fixturesThisWeek = response.data;
  });

  //Updating the scores the dependent of on the type of bet id
  $scope.addPrediction = function(prediction, fixtureId) {
    data = {};
    data.fixtureId = fixtureId;
    data.predictionGoalsHomeTeam = prediction.scores.predictionGoalsHomeTeam[fixtureId];
    data.predictionGoalsAwayTeam = prediction.scores.predictionGoalsAwayTeam[fixtureId];
    data.typeOfBet = prediction.typeOfBetId[fixtureId];
    $scope.madePredictions.push(data);
    console.log($scope.madePredictions)
  }
}]);
然而,我相信问题源于我的tips控制器中的方法,可能在第4行

def create
    @tip = Tip.new(params[:tip])
    @tip.save
    @prediction = Prediction.find(params[:prediction][:fixtureId])
    @prediction.predictionGoalsHomeTeam = params[:prediction][:predictionGoalsHomeTeam]
    @prediction.predictionGoalsHomeTeam = params[:prediction][:predictionGoalsAwayTeam]
    @prediction.save
    @tip.predictions << @prediction
    respond_with(@tip)
  end
def创建
@tip=tip.new(参数[:tip])
@提示:保存
@prediction=prediction.find(参数[:prediction][:fixtureId])
@prediction.predictionGoalsHomeTeam=参数[:prediction][:predictionGoalsHomeTeam]
@prediction.predictionGoalsHomeTeam=参数[:prediction][:predictionGoalsAwayTeam]
@预测。保存

@提示:预测有几个错误。。在create方法中,您将连续两次分配@prediction.predictionGoalsHomeTeam

@prediction.predictionGoalsHomeTeam = params[:prediction][:predictionGoalsHomeTeam]
@prediction.predictionGoalsHomeTeam = params[:prediction][:predictionGoalsAwayTeam]
因此,您需要将最后一个更改为AwayTeam,因为这是您从参数中得到的

您的主要问题是params[:prediction]是一个数组,因此
prediction.find(params[:prediction][:fixtureId])
无法工作,因为您试图获取不存在的数组的fixtureId。您需要在
参数[:prediction]
中循环,并将每个对象分别存储在
@tip.predictions
中。尝试使用以下方法:

  def create
    @tip = Tip.new(params[:tip])
    @tip.save
    params[:prediction].each do |p|
      @prediction = Prediction.find(p[:fixtureId])
      @prediction.predictionGoalsHomeTeam = p[:predictionGoalsHomeTeam]
      @prediction.predictionGoalsAwayTeam = p[:predictionGoalsAwayTeam]
      @prediction.save
      @tip.predictions << @prediction
    end
    respond_with(@tip)
  end
def创建
@tip=tip.new(参数[:tip])
@提示:保存
参数[:预测]。每个do | p|
@prediction=prediction.find(p[:fixtureId])
@prediction.predictionGoalsHomeTeam=p[:predictionGoalsHomeTeam]
@prediction.predictionGoalsAwayTeam=p[:predictionGoalsAwayTeam]
@预测。保存

@提示:这是Rails的错误。如果您在使用
create
方法显示的文件中看到引用第4行的错误,这意味着
Prediction.find
在需要整数时接收到一个符号。将
to_i
方法添加到params调用的末尾。不过,所有这些都只是猜测,没有看到错误,也不知道您的文件名和行号。嗨,错误在标题中,对不起,我没有指定