Rails: “Stack level too deep” error when calling “id” primary key method

前端 未结 2 1780
误落风尘
误落风尘 2021-01-22 02:10

This is a repost on another issue, better isolated this time. In my environment.rb file I changed this line:

config.time_zone = \'UTC\'

to this

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-22 03:00

    -- This answer is copied from my original post here.

    Finally solved! After posting a third question and with help of trptcolin, I could confirm a working solution.

    The problem: I was using require to include models from within Table-less models (classes that are in app/models but do not extend ActiveRecord::Base). For example, I had a class FilterCategory that performed require 'category'. This messed up with Rails' class caching. I had to use require in the first place since lines such as Category.find :all failed.

    The solution (credit goes to trptcolin): replace Category.find :all with ::Category.find :all. This works without the need to explicitly require any model, and therefore doesn't cause any class caching problems.

    The "stack too deep" problem also goes away when using config.active_record.default_timezone = :utc

提交回复
热议问题