“each”/“map” on array results in “You have a nil object when you didn't expect it” in create_time_zone_conversion_attribute?, sporadically

前端 未结 1 794
眼角桃花
眼角桃花 2021-01-17 03:31

I have a button which is sending a get request over XHR to a specific action in a rails server. This action calls a function I defined in the model \"Category\". This functi

相关标签:
1条回答
  • 2021-01-17 04:03

    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

    0 讨论(0)
提交回复
热议问题