I have a Post, and an User model
I want to enable users to save or bookmark posts. In other words, they will click a button and the post will be bookmarked/saved. Then the user will be able to see all those posts listed in a page (like YouTube’s watch later).
I think I have to create a Bookmark model. But I’m not sure what kind of assosiation the models should have with Post and User.
Any suggestions?
If you just want to have bookmarks but no other information associated with the bookmark like ‘bookmarked comment’ or ‘blah blah’ you can use
has_and_belongs_to_manyassociation. There you won’t need to create a bookmark model. You only need to create the join table in this case. Thehas_many :throughis useful in a case when you need to store more information with the relationship. You can go through this has_and_belongs_to_many_association for more information.