質問編集履歴

4

log追記

2019/11/17 08:32

投稿

Komama
Komama

スコア28

test CHANGED
File without changes
test CHANGED
@@ -125,3 +125,47 @@
125
125
  </table>
126
126
 
127
127
  ```
128
+
129
+
130
+
131
+ ■log
132
+
133
+ ```
134
+
135
+ Started POST "/clients?client_id=1" for ::1 at 2019-11-17 17:30:03 +0900
136
+
137
+ Processing by ClientsController#staff_memo_create as JS
138
+
139
+ Parameters: {"utf8"=>"✓", "authenticity_token"=>"a0H7tSfjXcColH9O7iAwVB4hcsWSh/jHzdJOOTcCI9j2gbL1/s5ZNhzqYjD1QddwKZwqZnaIoB2JXOL6ARwivQ==", "staff_memo_date"=>"2019-11-01", "staff_memo"=>"test", "commit"=>"Save ", "client_id"=>"1"}
140
+
141
+ Client Load (0.1ms) SELECT "clients".* FROM "clients" WHERE "clients"."id" = ? LIMIT ? [["id", 1], ["LIMIT", 1]]
142
+
143
+ ↳ app/controllers/clients_controller.rb:712
144
+
145
+ Unpermitted parameters: :utf8, :authenticity_token, :commit, :client_id
146
+
147
+ (0.1ms) begin transaction
148
+
149
+ ↳ app/controllers/clients_controller.rb:714
150
+
151
+ (0.2ms) commit transaction
152
+
153
+ ↳ app/controllers/clients_controller.rb:714
154
+
155
+ Redirected to http://localhost:3000/clients
156
+
157
+ Completed 200 OK in 8ms (ActiveRecord: 0.4ms)
158
+
159
+
160
+
161
+
162
+
163
+ Started GET "/clients" for ::1 at 2019-11-17 17:30:03 +0900
164
+
165
+ Processing by ClientsController#index as HTML
166
+
167
+ Rendering clients/index.html.erb within layouts/application
168
+
169
+ Rendered clients/_search.html.erb (2.7ms)
170
+
171
+ ```

3

viewに説明を追記

2019/11/17 08:32

投稿

Komama
Komama

スコア28

test CHANGED
File without changes
test CHANGED
@@ -112,6 +112,8 @@
112
112
 
113
113
  <tr>
114
114
 
115
+ #ここに上で入力されたstaff_memo_date, staff_memo内容を表示したい
116
+
115
117
  <td scope="row"><%= @client.staff_memo_date.present? ? @client.staff_memo_date : "-" %></td>
116
118
 
117
119
  <td scope="row"><%= @client.staff_memo.present? ? @client.staff_memo : "-" %></td>

2

ルーティング、コントローラー名を追記

2019/11/17 08:13

投稿

Komama
Komama

スコア28

test CHANGED
File without changes
test CHANGED
@@ -16,7 +16,69 @@
16
16
 
17
17
 
18
18
 
19
+ ■ルーティング
20
+
21
+ ```
22
+
23
+ get 'clients/(:id)', to:'clients#show', as: :client_show
24
+
25
+ post 'clients/(:id)', to:'clients#staff_memo_create', as: :staff_memo
26
+
27
+ ```
28
+
29
+ ■コントローラー
30
+
31
+ clients_controller.rb
32
+
33
+ ```
34
+
35
+ def show
36
+
37
+ @client = Client.find_by(id: params[:id])
38
+
39
+ end
40
+
41
+
42
+
43
+ def staff_memo_create
44
+
45
+ @client = Client.find_by(id: params[:client_id])
46
+
47
+
48
+
49
+ if @client.save(staff_memo)
50
+
51
+ flash[:success] = "登録が完了しました"
52
+
53
+ redirect_to client_show_url and return
54
+
55
+ else
56
+
57
+ flash[:danger] = "入力に不備があります"
58
+
59
+ render "clients/show"
60
+
61
+ end
62
+
63
+ end
64
+
65
+
66
+
67
+ private
68
+
69
+ def staff_memo
70
+
71
+ params.permit(:staff_memo_date, :staff_memo)
72
+
73
+ end
74
+
75
+ ```
76
+
77
+
78
+
19
- showページ
79
+ viewページ
80
+
81
+ clients#show.html.erb
20
82
 
21
83
  ```show.html.erb
22
84
 
@@ -61,51 +123,3 @@
61
123
  </table>
62
124
 
63
125
  ```
64
-
65
-
66
-
67
- ■コントローラー
68
-
69
- ```
70
-
71
- def show
72
-
73
- @client = Client.find_by(id: params[:id])
74
-
75
- end
76
-
77
-
78
-
79
- def staff_memo_create
80
-
81
- @client = Client.find_by(id: params[:client_id])
82
-
83
-
84
-
85
- if @client.save(staff_memo)
86
-
87
- flash[:success] = "登録が完了しました"
88
-
89
- redirect_to client_show_url and return
90
-
91
- else
92
-
93
- flash[:danger] = "入力に不備があります"
94
-
95
- render "clients/show"
96
-
97
- end
98
-
99
- end
100
-
101
-
102
-
103
- private
104
-
105
- def staff_memo
106
-
107
- params.permit(:staff_memo_date, :staff_memo)
108
-
109
- end
110
-
111
- ```

1

誤字があったため修正しました。

2019/11/17 08:08

投稿

Komama
Komama

スコア28

test CHANGED
@@ -1 +1 @@
1
- Rails : save時にコントローラーの処理はsuccessとなるがDBに保存されないr
1
+ Rails : save時にコントローラーの処理はsuccessとなるがDBに保存されない
test CHANGED
File without changes