回答編集履歴
1
追記
test
CHANGED
@@ -9,3 +9,59 @@
|
|
9
9
|
newの画像の様にしたいのですか?
|
10
10
|
|
11
11
|
new、edit のviewのソースもつけて下さい。
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
追記
|
16
|
+
|
17
|
+
<% for num in 1..9 do %> の中に有る<%= f.fields_for :players do |p| %>が全選手分を書き出させてます。newのときはorderにまだplayerが登録されていないので繰り返しがなかったのです。
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
ですので、ここは p に 打順に応じたplayerが入るようにしてループを削除する。
|
22
|
+
|
23
|
+
<% for num in 1..9 do %> を
|
24
|
+
|
25
|
+
<% @order.players.sort_by{|p| p.打順}.each do |p| %>
|
26
|
+
|
27
|
+
にする。
|
28
|
+
|
29
|
+
```
|
30
|
+
|
31
|
+
<% @order.players.sort_by{|p| p.打順}.each.with_index(1) do |p,num| %>
|
32
|
+
|
33
|
+
<tr>
|
34
|
+
|
35
|
+
<td class="td-num">
|
36
|
+
|
37
|
+
<%= num %>
|
38
|
+
|
39
|
+
</td>
|
40
|
+
|
41
|
+
<td class="td-position">
|
42
|
+
|
43
|
+
<%= p.collection_select :position_id, Position.all, :id, :name, :include_blank => true %>
|
44
|
+
|
45
|
+
</td>
|
46
|
+
|
47
|
+
<td class="td-card">
|
48
|
+
|
49
|
+
<%= p.collection_select :card_id, Card.all.order(:image_front), :id, :name, :include_blank => true %>
|
50
|
+
|
51
|
+
</td>
|
52
|
+
|
53
|
+
</tr>
|
54
|
+
|
55
|
+
<% end %>
|
56
|
+
|
57
|
+
```
|
58
|
+
|
59
|
+
ただschemaみたところ打順がない?
|
60
|
+
|
61
|
+
及び、newのときに予め9つplayerを作っておかないと9行並ばないので入力できなくなります。
|
62
|
+
|
63
|
+
(1..9).each{|打順| @order.plaiers.build(打順: 打順)}
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
打順 は適切な英単語に置き換えて下さい
|