質問編集履歴

2

修正

2016/11/26 09:56

投稿

vvvchrome
vvvchrome

スコア19

test CHANGED
File without changes
test CHANGED
@@ -1,17 +1,61 @@
1
- Twitterで実装されているアンケート機能をRuby on Railsで作ろうとしているのですが、データベース設計につ質問させていただきます。
1
+ Twitterで実装されているアンケート機能をRuby on Railsで作ろうとしているのですが、データの表示が出来なくて困ってるので質問させていただきます。
2
2
 
3
3
 
4
4
 
5
5
  Userモデル
6
6
 
7
- Pollモデル(中間) => user_id, question_id
7
+ Questionモデル => title, user_id
8
8
 
9
- Questionモデル => title
9
+ Pollモデル(中間) => question_id, choice_id
10
10
 
11
11
  Choiceモデル => content, question_id
12
12
 
13
13
 
14
14
 
15
- 上記の設計は正しいのでしょうか?
15
+ ```
16
16
 
17
+ class QuestionsController < ApplicationController
18
+
19
+ def index
20
+
21
+ @questions = Question.all
22
+
23
+ end
24
+
25
+ ...
26
+
27
+ ...
28
+
29
+ end
30
+
31
+ ```
32
+
33
+
34
+
35
+ ```
36
+
37
+ # index.html.haml
38
+
17
- 全然違う、もっと良い方法があるなどありましたらご教授願います。
39
+ - @questions.each do |question|
40
+
41
+ %li
42
+
43
+ = question.user.name
44
+
45
+ = question.title
46
+
47
+ = question.choice.content
48
+
49
+ ```
50
+
51
+
52
+
53
+ エラーメッセージ
54
+
55
+ undefined method `choice' for
56
+
57
+
58
+
59
+
60
+
61
+ どのようにしてchoicesテーブルのcontentカラムを表示するのでしょうか?

1

修正

2016/11/26 09:56

投稿

vvvchrome
vvvchrome

スコア19

test CHANGED
File without changes
test CHANGED
@@ -6,7 +6,9 @@
6
6
 
7
7
  Pollモデル(中間) => user_id, question_id
8
8
 
9
+ Questionモデル => title
10
+
9
- Questionモデル => title, choice1, choice2, choice3, choice4
11
+ Choiceモデル => content, question_id
10
12
 
11
13
 
12
14