Other Pages

Voting On Topics

Goals

  • Create a model for votes

  • Topics
    id
    title
    description
    Votes
    id
    topic_id

    Every topic in suggestotron can be voted on. In order to count votes, we need to record votes in the database. We'll add the new table for votes now. It contains a refrence to the topic.

Steps

Type this in the shell:
rails generate model vote topic:references
rails db:migrate

Explanation

  • Just like before, we're creating a new model named "vote"
  • votes contains just one thing: a reference to the topic it belongs to
  • We didn't generate a full scaffold this time because we aren't going to do the full CRUD for votes; they're just going to be considered part of topics as-is.

Next Step: