ActiveModel::MissingAttributeError occurs after deploying and then goes away after a while

前端 未结 7 1017
我寻月下人不归
我寻月下人不归 2020-12-25 09:58

I have a Rails 3.0.9 app that, once it is deployed, suffers from a bunch of ActiveModel::MissingAttributeErrors that crop up causing 500s. The errors occur fairly randomly,

7条回答
  •  清歌不尽
    2020-12-25 10:18

    I found an interesting take on this that resulted in the same error. In an attempt to reuse code we subclasses a presenters class with a presenters class that performed grouping to use in a graph view.

    To simplify, it was something like:

    class PostPresenter 
      def query
        Post.where(...stuff....).includes(:wombat)
      end
    end
    

    The the aggregator did something like the following to build a table of posts per day:

    class AggregatePostPresenter < PostPresenter
      def group_query
        query.select('count(*) as cnt, date(created_at)').group('date(created_at)')
      end
    end
    

    A call to "group_query" results in an ActiveModel::MissingAttributeError since, I think, the attempt to "includes" Wombat fails because "wombat_id" wasn't in the attributes included in the "select".

    This is probably not your answer, however, since it happens regardless of whether or not cache is enabled.

提交回复
热议问题