这个Rails4错误是什么意思?致命的:异常已重新进入...“在rollback_active_record_state中进行救援!” [英] What Does This Rails4 error mean? fatal: exception reentered ... `rescue in rollback_active_record_state!'

查看:57
本文介绍了这个Rails4错误是什么意思?致命的:异常已重新进入...“在rollback_active_record_state中进行救援!”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm getting a couple of errors in my Rails 4 appointment scheduling application that I can't seem to correct or figure out the root cause.

我的种子文件一直以众所周知的错误,堆栈级别太深而中断。但是,当我运行该方法时,我相信它会中断,就会出现这个不同的错误:

My seeds file keeps breaking with well known "error, stack level too deep". But when I run the method I believe it is breaking on, I get this different error:


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。

Going through my commit history, I am not aware of any changes made to the generate_time_slots! method, and it worked previously. I'm using Rails 4, Ruby 2.

推荐答案

所以我只是遇到了类似的问题,并出现了类似的错误消息。

So I just had a similar issue with a similar error message.

只是 ActiveRecord 处于有用状态,并告诉您您递归调用了相同的方法。基本上,不是说您用完了堆栈,而是查看它最初获得的跟踪并确定它实际上是重新输入的递归调用。

It is just that ActiveRecord is being "helpful" and telling you that you called the same method recursively. Basically rather than saying you ran out of stack it is looking at the trace it originally got and determining it is in fact a reentered recursive call.

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

At least, that solved my issue.

这篇关于这个Rails4错误是什么意思?致命的:异常已重新进入...“在rollback_active_record_state中进行救援!”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆