polymorphic association


I have a scenario where I want to save a author image and book image to assets table…

I am using a polymorphic association.

And author_name is inside the books table.

now when I save the image the imageable_type says “Book” for both. And off-course it’s a correct behavior, but I am just trying to figure out is there any way where I can save author image and imageable_type should have “AuthorImage” and it should call the same Book model

Solution: Other solution I am thinking to separate the Author from book and have it in another table.

Please it will be really helpful if someone can help me out.


I think you're adding only book_images and no author_images at all. But
I'm nbot sure, because you're not providing your code

Try something like this:
@asset.imageable = @author
AuthorImage.create attributes

I don't know if you made the right decision with using polymorphic
associations. You need to provide more information what your
associations are. For example: Author has_many Images OR Author has_one
And can the image belong to a book and an author as well?