Rails.cache error in Rails 3.1 - TypeError: can't dump hash with default proc

后端 未结 4 1000
滥情空心
滥情空心 2020-11-29 04:23

I running into an issue with the Rails.cache methods on 3.1.0.rc4 (ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10]). The code works fine within the same applic

4条回答
  •  余生分开走
    2020-11-29 05:10

    I realized that using where or some scope created ActiveRecord::Relation objects. I then noticed that doing a simple Model.find worked. I suspected that it didn't like the ActiveRecord::Relation object so I forced conversion to a plain Array and that worked for me.

    Rails.cache.fetch([self.id, 'relA']) do
      relA.where(
          attr1: 'some_value'
      ).order(
          'attr2 DESC'
      ).includes(
          :rel_1,
          :rel_2
      ).decorate.to_a
    end
    

提交回复
热议问题