You wouldn't use a VotesController, you would create votes via other models which have a polymorphic relationship with them. In your example above, you would create them via:
post.votes
(assuming post
was an instance of Post
)
The idea behind polymorphic relationships is a many-to-many relationship with multiple models, so you should be creating any 'votable' records via the source models, in this example, Post
.
For instance, you could create a vote
method in your PostController
that would create the vote association as I've outlined above and then add the appropriate route to submit your voting form.
Additionally, your Vote
model could also contain other data, depending on how you want to use voting. For instance, if you wanted to track the number of votes a model gets, you could add a count
column. In which case, you would create the record as:
post.votes.count += 1