Mongoid: NoMethodError: undefined method `sub’ for :section:Symbol

If you recently added a Mongoid relationship that defines a specific “class_name” so that you can have a custom relationship name, and you’re getting an error like

“NoMethodError: undefined method `sub’ for :yourclassname:Symbol”

it might be coming from Mongoid::Relations::Metadata.class_name, which assumes that class_name is a string, not a symbol. Change the class_name on your relationship definition to a string, and it should be fixed.

4 thoughts on “Mongoid: NoMethodError: undefined method `sub’ for :section:Symbol”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.