这个Rails4错误是什么意思?致命:异常重新进入...`在rollback_active_record_state中救援!'

时间:2014-09-30 13:06:44

标签: ruby-on-rails ruby activerecord

我在Rails 4预约安排应用程序中遇到了一些错误,我似乎无法纠正或找出根本原因。

我的种子文件一直以众所周知的错误打破#34;错误,堆栈级别太深"。但是,当我运行该方法时,我相信它正在打破,我得到了这个不同的错误:

Seeding time slots for workday no. 1
   (0.5ms)  SAVEPOINT active_record_1
   (0.5ms)  ROLLBACK TO SAVEPOINT active_record_1
fatal: exception reentered
from /Users/rskelley/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-4.1.5/lib/active_record/transactions.rb:286:in `rescue in rollback_active_record_state!'

涉及的文件如下。

Seeds.rb

puts "Seeding Workdays."

day_numbers = (1..5).to_a
5.times do
  start_time = WorkDay.time_slot_format(9)
  end_time = WorkDay.time_slot_format([5,6][rand(2)])
  rand_date = Date.today + day_numbers.slice!(0)
  WorkDay.create(start_time: start_time, end_time: end_time, date: rand_date )
end

puts "Generating Time Slots for each WorkDay"

workdays = WorkDay.all
workday_number = 1

workdays.each do |workday|
  calendar_manager = CalendarManager.new(workday: workday, date: workday.date)
  puts "Seeding time slots for workday no. #{workday_number}"
  workday_number += 1
  calendar_manager.generate_time_slots!
end

calendar_manager.rb

include ActiveModel::Validations
include ActiveModel::Conversion
extend ActiveModel::Naming
extend AppointmentTools

attr_accessor :workday, :date, :slot_length

 def generate_time_slots!(increment=15)
    # Space between start and end
    @slot_length ||= increment

    day = self.workday.date
    hour = 9
    minute = 0
    @time_slots = Array.new

    33.times do
      beginning = TimeOfDay.parse(hour) + minute.minutes
      ending = beginning + @slot_length.minutes
      time_slot = TimeSlot.create work_day_id: self.workday.id, start_time: beginning.strftime("%I:%M %p"), end_time: ending.strftime("%I:%M %p"), date: day
      @time_slots << time_slot
      minute += @slot_length
    end
  end

通过我的提交历史记录,我不知道对generate_time_slots进行了任何更改!方法,它以前工作。我使用的是Rails 4,Ruby 2。

1 个答案:

答案 0 :(得分:23)

所以我遇到了类似的错误信息。

只是 ActiveRecord 正在“有用”,并告诉您递归调用了相同的方法。基本上,而不是说你没有堆栈,它正在查看它最初获得的跟踪,并确定它实际上是一个重新进入的递归调用。

至少,这解决了我的问题。