回答編集履歴

5

誤字の修正

2019/04/17 05:03

投稿

ruby_math
ruby_math

スコア90

test CHANGED
@@ -46,7 +46,7 @@
46
46
 
47
47
 
48
48
 
49
- ===========================================================================
49
+ =======================================================================
50
50
 
51
51
 
52
52
 

4

誤字の修正

2019/04/17 05:03

投稿

ruby_math
ruby_math

スコア90

test CHANGED
@@ -64,7 +64,7 @@
64
64
 
65
65
  if @company = Company.find(params[:id])
66
66
 
67
- @company.updated_user_id == current_user.id
67
+ @company.updated_user_id = current_user.id
68
68
 
69
69
  @company.update(company_params)
70
70
 

3

誤字を削除

2019/04/17 04:47

投稿

ruby_math
ruby_math

スコア90

test CHANGED
@@ -60,10 +60,6 @@
60
60
 
61
61
 
62
62
 
63
- company_params[:updated_user_id] = current_user.id #deviseを利用
64
-
65
-
66
-
67
63
  respond_to do |format|
68
64
 
69
65
  if @company = Company.find(params[:id])

2

回答を追記

2019/04/17 04:45

投稿

ruby_math
ruby_math

スコア90

test CHANGED
@@ -43,3 +43,53 @@
43
43
 
44
44
 
45
45
  上記を試してみてください。
46
+
47
+
48
+
49
+ ===========================================================================
50
+
51
+
52
+
53
+ 確かにHidden_fieldは危険ですね、以下を試してみてください。
54
+
55
+
56
+
57
+ ```rb
58
+
59
+ def update
60
+
61
+
62
+
63
+ company_params[:updated_user_id] = current_user.id #deviseを利用
64
+
65
+
66
+
67
+ respond_to do |format|
68
+
69
+ if @company = Company.find(params[:id])
70
+
71
+ @company.updated_user_id == current_user.id
72
+
73
+ @company.update(company_params)
74
+
75
+ format.html { redirect_to company_path, notice: 'Company was successfully updated.' }
76
+
77
+ format.json { render :show, status: :ok, location: @company }
78
+
79
+ else
80
+
81
+ format.html { render :edit }
82
+
83
+ format.json { render json: @company.errors, status: :unprocessable_entity }
84
+
85
+ end
86
+
87
+ end
88
+
89
+ end
90
+
91
+ ```
92
+
93
+
94
+
95
+ こちらでいかがでしょうか?

1

追記

2019/04/17 04:45

投稿

ruby_math
ruby_math

スコア90

test CHANGED
@@ -26,7 +26,7 @@
26
26
 
27
27
 
28
28
 
29
- <%# 隠しフォーム %>
29
+ <%# 隠しフォーム @updated_user_idをvalueとして持たせてあげることで現在ログインされているユーザーのIDが送られる %>
30
30
 
31
31
  <%= f.hidden_field :updated_user_id, value:"#{@updated_user_id}" %>
32
32