I have a Slide class which optionally belongs to an instance of a "slideable" class:
belongs_to :slideable, polymorphic: true
Line 79 of draft.rb assumes that calling my_item.slideable_type will always return a string that can be constantized to find the associated class.
my_item.send(association.foreign_key.sub('_id', '_type')).constantize
However, in my case, because I don't have slideable_type defined until I actually have a slideable associated which results in this error:
NoMethodError: undefined method `constantize' for nil:NilClass
I think I can work around this by having a default value for slideable_type set in Postgres but it seems like it might be fairly easy to add some logic to check if the polymorphic type is defined/valid when trying to determine the association class.
I have a Slide class which optionally belongs to an instance of a "slideable" class:
belongs_to :slideable, polymorphic: trueLine 79 of draft.rb assumes that calling
my_item.slideable_typewill always return a string that can be constantized to find the associated class.my_item.send(association.foreign_key.sub('_id', '_type')).constantizeHowever, in my case, because I don't have
slideable_typedefined until I actually have a slideable associated which results in this error:NoMethodError: undefined method `constantize' for nil:NilClass
I think I can work around this by having a default value for slideable_type set in Postgres but it seems like it might be fairly easy to add some logic to check if the polymorphic type is defined/valid when trying to determine the association class.