質問編集履歴

2

誤字

2020/11/11 18:09

投稿

moST
moST

スコア14

test CHANGED
File without changes
test CHANGED
@@ -20,7 +20,7 @@
20
20
 
21
21
  ```
22
22
 
23
- <ActionController::Parameters {"array"=>[{"cnt"=>"51"}], "controller"=pi/combats", "action"=>"create"} permitted: false>
23
+ <ActionController::Parameters {"array"=>[{"cnt"=>"51"}], "controller"=pi/array", "action"=>"create"} permitted: false>
24
24
 
25
25
  ```
26
26
 
@@ -160,7 +160,7 @@
160
160
 
161
161
  modelSave: async function () {
162
162
 
163
- const res = await axios.post('/api/array/create', {array: this.Array})
163
+ const res = await axios.post('/api/array', {array: this.Array})
164
164
 
165
165
  if (res.status !== 201) {
166
166
 
@@ -184,7 +184,7 @@
184
184
 
185
185
  Get: async function() {
186
186
 
187
- const res = await axios.get(` /api/array/index`)
187
+ const res = await axios.get(` /api/array`)
188
188
 
189
189
  if (res.status !== 200) { process.exit() }
190
190
 

1

情報の最新化

2020/11/11 18:09

投稿

moST
moST

スコア14

test CHANGED
@@ -1 +1 @@
1
- Rails+Vueで、Vue側の値の変更ータ保存したい
1
+ Vue送信した配列(JSON)の値をストロングパラメーターしようとするとNoMethodErrorエラーなる
test CHANGED
@@ -4,9 +4,51 @@
4
4
 
5
5
  Vue側での値の変更をRailsのモデルに反映するPostリクエストはどのようにすればよいでしょうか?
6
6
 
7
- 配列引数にpostリクエストを、404エラー帰っます。
7
+ 今回は、ボタンすと1つ増える仕組みで試験します。
8
8
 
9
+
10
+
11
+ 11/12追記(タイトル変更)
12
+
13
+ byebugで確認したところ、paramsとparams.fetchの値は入っていましたが、permitでエラーになっています。
14
+
9
- 今回は、ボタンを押すと値が1つ増える仕組み試験しています。
15
+ paramsparams.fetchのは以下の通りです。
16
+
17
+
18
+
19
+ paramsの結果
20
+
21
+ ```
22
+
23
+ <ActionController::Parameters {"array"=>[{"cnt"=>"51"}], "controller"=pi/combats", "action"=>"create"} permitted: false>
24
+
25
+ ```
26
+
27
+
28
+
29
+ params.fetch(:array, {})の結果
30
+
31
+ ```
32
+
33
+ [<ActionController::Parameters {"cnt"=>"51"} permitted: false>]
34
+
35
+
36
+
37
+ ```
38
+
39
+ params.fetch(:array, {}).permit(:cnt)の結果
40
+
41
+ ```
42
+
43
+ *** NoMethodError Exception: undefined method `permit' for #<Array:0x00007ff8350162d0>
44
+
45
+ nil
46
+
47
+ ```
48
+
49
+
50
+
51
+
10
52
 
11
53
 
12
54
 
@@ -28,7 +70,9 @@
28
70
 
29
71
  def create
30
72
 
73
+ @test = Array.find(current_user.id)
74
+
31
- current_user.Array.create!(array_params)
75
+ @test.update(array_params)
32
76
 
33
77
  head :created
34
78
 
@@ -42,7 +86,7 @@
42
86
 
43
87
  def array_params
44
88
 
45
- params.require(:array).permit(:cnt)
89
+ params.fetch(:array, {}).permit(:cnt)
46
90
 
47
91
  end
48
92