回答編集履歴
7
わ
answer
CHANGED
@@ -21,3 +21,20 @@
|
|
21
21
|
end
|
22
22
|
```
|
23
23
|
|
24
|
+
追記
|
25
|
+
|
26
|
+
以下の様な感じでできそうです。
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
artist.ganres.clear
|
30
|
+
artist.genres << ジャンルのモデルの配列
|
31
|
+
```
|
32
|
+
|
33
|
+
以下でもいいかも知れません
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
artists.genre_ids = ジャンルのidの配列
|
37
|
+
```
|
38
|
+
|
39
|
+
|
40
|
+
|
6
ミス
answer
CHANGED
@@ -1,14 +1,12 @@
|
|
1
1
|
アーティストのジャンルを編集する操作は、DBのテーブルの`artists_ganres`を変更することになりますよね?
|
2
2
|
ですから更新とはこのテーブルの行の削除or追加という事になります。
|
3
3
|
|
4
|
-
なので、create(destroy)を使うことになります。
|
5
|
-
|
6
4
|
[参考](http://railsdoc.com/references/has_and_belongs_to_many)
|
7
5
|
|
8
6
|
こんな感じです。
|
9
7
|
|
10
8
|
```ruby
|
11
|
-
artist.genres
|
9
|
+
artist.genres << ganre
|
12
10
|
```
|
13
11
|
|
14
12
|
更新は一度関連を全部消してから必要な関係を順に作ればいいと思います。
|
@@ -19,7 +17,7 @@
|
|
19
17
|
artist.ganres.clear
|
20
18
|
ganres = ジャンルのモデルの配列
|
21
19
|
ganres.each do |ganre|
|
22
|
-
artist.genres
|
20
|
+
artist.genres << ganre
|
23
21
|
end
|
24
22
|
```
|
25
23
|
|
5
ミス
answer
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
アーティストのジャンルを編集する操作は、DBのテーブルの`artists_ganres`を変更することになりますよね?
|
2
2
|
ですから更新とはこのテーブルの行の削除or追加という事になります。
|
3
3
|
|
4
|
-
なので、createを使うことになります。
|
4
|
+
なので、create(destroy)を使うことになります。
|
5
5
|
|
6
|
+
[参考](http://railsdoc.com/references/has_and_belongs_to_many)
|
7
|
+
|
6
8
|
こんな感じです。
|
7
9
|
|
8
10
|
```ruby
|
@@ -15,7 +17,7 @@
|
|
15
17
|
|
16
18
|
```ruby
|
17
19
|
artist.ganres.clear
|
18
|
-
ganres = ジャンルの
|
20
|
+
ganres = ジャンルのモデルの配列
|
19
21
|
ganres.each do |ganre|
|
20
22
|
artist.genres.create(ganre)
|
21
23
|
end
|
4
a
answer
CHANGED
@@ -1,15 +1,20 @@
|
|
1
1
|
アーティストのジャンルを編集する操作は、DBのテーブルの`artists_ganres`を変更することになりますよね?
|
2
|
+
ですから更新とはこのテーブルの行の削除or追加という事になります。
|
2
3
|
|
3
|
-
で、
|
4
|
+
なので、createを使うことになります。
|
4
5
|
|
6
|
+
こんな感じです。
|
7
|
+
|
8
|
+
```ruby
|
5
9
|
artist.genres.create
|
10
|
+
```
|
6
11
|
|
7
12
|
更新は一度関連を全部消してから必要な関係を順に作ればいいと思います。
|
8
13
|
|
9
14
|
こんな感じかな?もっといいやり方があるかも知れません。
|
10
15
|
|
11
16
|
```ruby
|
12
|
-
artist.
|
17
|
+
artist.ganres.clear
|
13
18
|
ganres = ジャンルのidの配列
|
14
19
|
ganres.each do |ganre|
|
15
20
|
artist.genres.create(ganre)
|
3
わかりやすく
answer
CHANGED
@@ -1,22 +1,18 @@
|
|
1
1
|
アーティストのジャンルを編集する操作は、DBのテーブルの`artists_ganres`を変更することになりますよね?
|
2
2
|
|
3
|
-
ですから、`collection`メソッドを利用して変更することになります。
|
4
|
-
|
5
|
-
[参考](http://railsdoc.com/references/has_and_belongs_to_many)
|
6
|
-
|
7
3
|
で、それに対してcreateを順に発行すればよいです。
|
8
4
|
|
9
|
-
artist.
|
5
|
+
artist.genres.create
|
10
6
|
|
11
7
|
更新は一度関連を全部消してから必要な関係を順に作ればいいと思います。
|
12
8
|
|
13
9
|
こんな感じかな?もっといいやり方があるかも知れません。
|
14
10
|
|
15
11
|
```ruby
|
16
|
-
artist.
|
12
|
+
artist.genres.clear
|
17
13
|
ganres = ジャンルのidの配列
|
18
14
|
ganres.each do |ganre|
|
19
|
-
artist.
|
15
|
+
artist.genres.create(ganre)
|
20
16
|
end
|
21
17
|
```
|
22
18
|
|
2
わかりやすくした
answer
CHANGED
@@ -6,4 +6,17 @@
|
|
6
6
|
|
7
7
|
で、それに対してcreateを順に発行すればよいです。
|
8
8
|
|
9
|
-
artist.collection.create
|
9
|
+
artist.collection.create
|
10
|
+
|
11
|
+
更新は一度関連を全部消してから必要な関係を順に作ればいいと思います。
|
12
|
+
|
13
|
+
こんな感じかな?もっといいやり方があるかも知れません。
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
artist.collection.clear
|
17
|
+
ganres = ジャンルのidの配列
|
18
|
+
ganres.each do |ganre|
|
19
|
+
artist.collection.create(ganre)
|
20
|
+
end
|
21
|
+
```
|
22
|
+
|
1
ミス
answer
CHANGED
@@ -1,11 +1,9 @@
|
|
1
1
|
アーティストのジャンルを編集する操作は、DBのテーブルの`artists_ganres`を変更することになりますよね?
|
2
2
|
|
3
|
-
ですから、
|
3
|
+
ですから、`collection`メソッドを利用して変更することになります。
|
4
4
|
|
5
|
-
|
5
|
+
[参考](http://railsdoc.com/references/has_and_belongs_to_many)
|
6
6
|
|
7
|
-
|
7
|
+
で、それに対してcreateを順に発行すればよいです。
|
8
8
|
|
9
|
-
|
9
|
+
artist.collection.create
|
10
|
-
|
11
|
-
[参考:Rails Tutorial12章](http://railstutorial.jp/chapters/following_users?version=4.2#cha-following_users)
|