Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when publishing a draft that has a polymorphic association if the association is nil #62

Open
andymcintosh opened this issue Mar 21, 2017 · 1 comment · May be fixed by #81
Open

Comments

@andymcintosh
Copy link

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.

andymcintosh added a commit to andymcintosh/draftsman that referenced this issue Mar 21, 2017
Added logic around determining if polymorphic associations are
draftable dependencies
@andymcintosh
Copy link
Author

Committed a fix to my fork. I'll put together tests and a pull request when I get a few minutes.

JeremiahChurch pushed a commit to JeremiahChurch/draftsman that referenced this issue Jun 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants