goals {
goal "Create a model for votes"
div(style: 'margin: 0 auto; width: 250px; height: 120px;') do
model_diagram header: 'Topics', fields: %w(id title description), style: "float: left;"
div(style: 'float: left; position: relative; width: 60px; height: 100px;') do
div(class: 'arrow-left', style: 'left: 0; top: 30px;')
div(class: 'horiz-line', style: 'left: 5px; top: 37px; width: 25px;')
div(class: 'vert-line', style: 'left: 30px; top: 38px; height: 25px;')
div(class: 'horiz-line', style: 'right: 0; top: 62px; width: 30px;')
end
model_diagram header: 'Votes', fields: %w(id topic_id), style: "float: left;"
end
message <<-MARKDOWN
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.
MARKDOWN
}
steps {
console <<-SHELL
rails generate model vote topic:references
rails db:migrate
SHELL
}
explanation {
message <<-MARKDOWN
* 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.
MARKDOWN
}
next_step "hooking_up_votes_and_topics"