Other Pages

Expand All

voting_on_topics.step

goals do
  goal "Create a model for votes"

  model_diagram header: 'Votes', fields: %w(id topic_id)

  message "Every topic in suggestotron can be voted on. In order to count votes, we need to record votes. We'll add that table now."
end

steps do
  console <<-SHELL
rails generate model vote topic_id:integer
rails db:migrate
  SHELL
end

explanation do
  message <<-MARKDOWN
  * Just like before, we're creating a new model named "vote".
  * The only thing really different is the integer we added called `topic_id`.
    * `topic_id` is the data we need to draw the line between votes and topics.
  * 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.
  MARKDOWN
end

next_step "hooking_up_votes_and_topics"