SpinaCMS / Spina

Spina CMS
http://www.spinacms.com
Other
2.19k stars 405 forks source link

Spina Pro breaks eager_load - undefined method attr_json_accepts_nested_attributes_for #1088

Closed alehlopeh closed 2 years ago

alehlopeh commented 2 years ago

The problem

With latest Spina (2.11.0) and Spina Pro (0.8.0), when Rails.application.config.eager_load is set to true, Rails application fails to start. The error:

`method_missing': undefined method `attr_json_accepts_nested_attributes_for' for #<Class:0x0000000116dbff08> (NoMethodError)

The cause

TLDR; The class Spina::Pro::PageRevision is missing include AttrJson::NestedAttributes

Background TranslatedContent calls the method attr_json_accepts_nested_attributes_for which comes from AttrJson::NestedAttributes, but TranslatedContent does not explicitly include AttrJson::NestedAttributes. The assumption is that any class that includes TranslatedContent will include AttrJson::NestedAttributes too. However, Spina::Pro::PageRevision does not.

With eager_load set to false, the same exception is raised the very first time PageRevision is accessed. Subsequent attempts to access PageRevision work as expected.

How to reproduce

This happens in a brand new rails app with Spina pro:

  1. Create a rails app and add spina pro, following all instructions.
  2. Set eager_load to true in config/environments/development.rb
  3. Run rails server or console
  4. See error

This seems like kind of a big deal since Rails sets eager_load to true in production by default.

Bramjetten commented 2 years ago

Woops, sorry for that! Will publish a patch in a bit.

Bramjetten commented 2 years ago

Published Spina Pro 0.8.1 which should fix this

alehlopeh commented 2 years ago

@Bramjetten Thanks for getting that fixed so quickly!