Skip to content

Commit 0734e2e

Browse files
committed
finished voting model
1 parent 718772e commit 0734e2e

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

sites/en/intro-to-rails/hooking_up_votes_and_topics.step

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ end
2929
end
3030

3131
step "Teach the Vote model about Topics" do
32-
message "Edit `app/models/vote.rb` so that it looks like this:"
32+
message "Look into `app/models/vote.rb` and confirm that it looks like this:"
3333
source_code :ruby, <<-RUBY
3434
class Vote < ApplicationRecord
3535
belongs_to :topic
@@ -43,7 +43,7 @@ end
4343
console_with_message "Next, open a Rails console in a terminal window:", "rails c"
4444

4545
result <<-CONSOLE
46-
$ rails c
46+
$ rails console
4747
Loading development environment (Rails 5.0.0)
4848
2.3.0 :001 >
4949
CONSOLE

sites/en/intro-to-rails/voting_on_topics.step

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,35 @@
22
goals {
33
goal "Create a model for votes"
44

5-
model_diagram header: 'Votes', fields: %w(id topic_id)
5+
div(style: 'margin: 0 auto; width: 250px; height: 120px;') do
6+
model_diagram header: 'Topics', fields: %w(id title description), style: "float: left;"
7+
div(style: 'float: left; position: relative; width: 60px; height: 100px;') do
8+
div(class: 'arrow-left', style: 'left: 0; top: 30px;')
9+
div(class: 'horiz-line', style: 'left: 5px; top: 37px; width: 25px;')
10+
div(class: 'vert-line', style: 'left: 30px; top: 38px; height: 25px;')
11+
div(class: 'horiz-line', style: 'right: 0; top: 62px; width: 30px;')
12+
end
13+
model_diagram header: 'Votes', fields: %w(id topic_id), style: "float: left;"
14+
end
615

7-
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."
16+
message <<-MARKDOWN
17+
Every topic in suggestotron can be voted on.
18+
In order to count votes, we need to record votes in the database.
19+
We'll add the new table for votes now.
20+
MARKDOWN
821
}
922

1023
steps {
1124
console <<-SHELL
12-
rails generate model vote topic_id:integer
25+
rails generate model vote references:topic
1326
rails db:migrate
1427
SHELL
1528
}
1629

1730
explanation {
1831
message <<-MARKDOWN
1932
* Just like before, we're creating a new model named "vote"
20-
* The only thing really different is the integer we added called `topic_id`.
21-
* `topic_id` is the data we need to draw the line between votes and topics.
33+
* `votes` contains just one thing: a reference to the topic it belongs to
2234
* We didn't generate a full scaffold this time because we aren't
2335
going to do the full CRUD for votes; they're just going to be
2436
considered part of topics as-is.

0 commit comments

Comments
 (0)