0

我正在将我的应用程序升级到最新的 rails 并且一直在努力解决堆栈级别太深的错误。当我从我的模型发出 ajax 请求时会发生此错误。这是错误和相关的控制器/型号代码:

错误

[679c54ab63bbaad55d7a1bd1fd9246d7] [127.0.0.1] Processing by CoachesController#new as */*
[679c54ab63bbaad55d7a1bd1fd9246d7] [127.0.0.1]   Parameters: {"date"=>"2013-06-11", "athlete_id"=>"2"}
[679c54ab63bbaad55d7a1bd1fd9246d7] [127.0.0.1]   User Load (24.1ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
[679c54ab63bbaad55d7a1bd1fd9246d7] [127.0.0.1]   User Load (0.3ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 2 LIMIT 1
[679c54ab63bbaad55d7a1bd1fd9246d7] [127.0.0.1]    (0.2ms)  SELECT COUNT(*) FROM "log_entries" WHERE "log_entries"."athlete_id" = 2 AND (date == '2013-06-11')
[679c54ab63bbaad55d7a1bd1fd9246d7] [127.0.0.1] Completed 500 Internal Server Error in 60ms
[679c54ab63bbaad55d7a1bd1fd9246d7] [127.0.0.1] 
SystemStackError (stack level too deep):
  actionpack (3.2.0) lib/action_dispatch/middleware/reloader.rb:70

控制器

   def new
@athlete = User.find_by_id(params[:athlete_id])   #this is different in normal controller(non coach)
@date = Date.parse(params[:date])
if LogEntry.cal_entry(@date, @athlete.id).size == 0 #check to see if entry exists
  @log_entry = @athlete.log_entries.build
  @log_entry1 = @log_entry.clone
  @workouts = @log_entry.workouts.build
  planned_workouts = @workouts.planned_workouts.build
  n = 1
  1.times do #do not generate more than the zone 1 
    planned_workouts.planned_workout_times.build(:zone => n)
    n += 2
  end
  completed_workouts = @workouts.completed_workouts.build
  n = 1
  1.times do
    completed_workouts.workout_times.build(:zone => n)
    n += 2
  end

else                                                #use already existing LogEntry
  @log_entry1 = LogEntry.cal_entry(@date, @athlete.id).first
  @log_entry = @athlete.log_entries.build
  @log_entry = @log_entry1.clone
  @workouts = @log_entry1.workouts.build
  planned_workouts = @workouts.planned_workouts.build
  n = 1 
  1.times do
    planned_workouts.planned_workout_times.build(:zone => n)
    n += 2
  end
  completed_workouts = @workouts.completed_workouts.build
  n = 1
  1.times do
    completed_workouts.workout_times.build(:zone => n)
    n += 2
  end 
end

^^ 这是调用 .cal_entry 模型函数时似乎发生错误的地方

模型

  scope :log_entry_for_date, lambda { |date1| where('date == ?', date1)}
  scope :log_entry_for_athlete, lambda { |athlete_id| where(:athlete_id => athlete_id)}

  def self.cal_entry(date, athlete_id)
    log_entry_for_date(date).log_entry_for_athlete(athlete_id).includes({:workouts => {:completed_workouts => :workout_times}})
  end

现在这在 rails 3.0 中完美运行,但在升级后立即显示错误。我尝试升级到 rails 3.2 但错误仍然存​​在。

红宝石 1.9.3p429

导轨 3.2.0

谢谢你的帮助!

4

1 回答 1

1

似乎该错误是由名为“method”的锻炼模型中一个名称不佳的方法引起的(用于说明)我想在升级之前这不是问题。

于 2013-06-26T20:46:19.103 回答