質問編集履歴

10

コードの変更

2020/01/31 07:28

投稿

YousukeTanaka
YousukeTanaka

スコア79

test CHANGED
File without changes
test CHANGED
@@ -216,41 +216,195 @@
216
216
 
217
217
  ```
218
218
 
219
- <%= simple_form_for(user, url: user_profile_update_path(current_user), method: :put, html:{ multipart: true }) do |f| %>
219
+ <%= simple_form_for(user, url: user_profile_update_path(user), method: :put, html:{ multipart: true }) do |f| %>
220
+
220
-
221
+ <%= f.error_notification %>
222
+
221
-
223
+ <%= f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present? %>
222
-
224
+
225
+
226
+
227
+
228
+
223
- //親テーブルの要素
229
+ //ここは、親テーブルのhtml要素
230
+
231
+ <div class="form-group row">
232
+
233
+ <label for="inputEmail3" class="col-sm-3 col-form-label">Fullname</label>
234
+
235
+ <div class="col-sm-9">
224
236
 
225
237
  <%= f.input :fullname, label: false, input_html: { value: current_user.fullname, class: "form-control" }, required: true, autofocus:true %>
226
238
 
227
-
239
+ </div>
240
+
228
-
241
+ </div>
242
+
229
-
243
+ <div class="form-group row">
244
+
230
-
245
+ <label for="inputEmail3" class="col-sm-3 col-form-label">Email</label>
246
+
231
-
247
+ <div class="col-sm-9">
248
+
232
-
249
+ <%= f.input :email, label: false, input_html: { value: current_user.email, class: "form-control"}, required: true, autofocus: true %>
250
+
251
+ </div>
252
+
253
+ </div>
254
+
255
+ <div class="form-group row">
256
+
257
+ <label for="filenam" class="col-sm-3 col-form-label">Photo</label>
258
+
259
+ <div class="col-sm-9">
260
+
261
+ <div class="row">
262
+
263
+ <div class="col-md-8">
264
+
265
+ <div class="text-left" style="padding-bottom: 1rem;">
266
+
267
+ <% if user.avatar.attached? %>
268
+
269
+ <%= image_tag user.avatar.variant(resize: "200x200"), class: "rounded img-thumbnail" %>
270
+
271
+ <% end %>
272
+
273
+ </div>
274
+
275
+ <div class="input-group">
276
+
277
+ <div class="input-group-prepend">
278
+
279
+ <div class="input-group-text" id="select_file_button">Click!</div>
280
+
281
+ </div>
282
+
283
+ <!-- <input id="filename" readonly type="text" value="""> -->
284
+
285
+ <input id="filename" readonly type="text" value="<%= user.avatar.filename if user.avatar.attached? %>" class="form-control" aria-describedby="select_file_button">
286
+
287
+ <%= f.input :avatar, label: false, as: :file, required: true, input_html: { class: "form-control-file", id:'file_button'}, wrapper: false %>
288
+
289
+ </div>
290
+
291
+ </div>
292
+
293
+ </div>
294
+
295
+ </div>
296
+
297
+ </div>
298
+
299
+
300
+
301
+
302
+
233
- //子テーブルの要素=>この部分が全て表示されない状況です。
303
+ //以下は、子テーブルのhtml要素
234
-
304
+
235
- <%= f.simple_fields_for :student do |p| %>
305
+ <%= f.simple_fields_for :student, @user.student do |p| %>
306
+
236
-
307
+ <div class="form-group row">
308
+
237
-
309
+ <label for="inputPassword3" class="col-sm-3 col-form-label">Nickname</label>
310
+
311
+ <div class="col-sm-9">
238
312
 
239
313
  <%= p.input :nickname, label: false, required: true, autofocus: true, input_html: { class: "form-control"}, wrapper: false, label_html: { class: "label" } %>
240
314
 
241
-
315
+ </div>
316
+
317
+ </div>
318
+
319
+ <div class="form-group row">
320
+
321
+ <label for="inputPassword3" class="col-sm-3 col-form-label">Birthday</label>
322
+
323
+ <div class="col-sm-9 d-flex flex-row justify-content-between align-items-center">
324
+
325
+ <%= p.input :birth,
326
+
327
+ label: false,
328
+
329
+ required: true,
330
+
331
+ input_html: { class: "form-control mx-1"},
332
+
333
+ wrapper: false,
334
+
335
+ as: :date,
336
+
337
+ start_year: Date.today.year - 60,
338
+
339
+ end_year: Date.today.year - 6, discard_day: true,
340
+
341
+ order: [:month, :year] %>
342
+
343
+ </div>
344
+
345
+ </div>
346
+
347
+ <fieldset class="form-group">
348
+
349
+ <div class="row">
350
+
351
+ <legend class="col-form-label col-sm-3 pt-0">Gender</legend>
352
+
353
+ <div class="col-sm-9">
354
+
355
+ <div class="form-check">
356
+
357
+ <%= p.input :gender,
358
+
359
+ :label => false,
360
+
361
+ :collection => [[0, 'Male'], [1, 'Female']],
362
+
363
+ :label_method => :last,
364
+
365
+ :value_method => :first,
366
+
367
+ :item_wrapper_class => 'inline',
368
+
369
+ :input_html => { class: "form-check-input" },
370
+
371
+ :as => :radio_buttons %>
372
+
373
+ </div>
374
+
375
+ </div>
376
+
377
+ </div>
378
+
379
+ </fieldset>
380
+
381
+ <div class="form-group row">
382
+
383
+ <label for="inputPassword3" class="col-sm-3 col-form-label">Self Introduction</label>
384
+
385
+ <div class="col-sm-9">
242
386
 
243
387
  <%= p.input :comment, label: false, as: :text, required: true, autofocus: true, input_html: { class: "form-control", rows: 7}, wrapper: false, label_html: { class: "label" } %>
244
388
 
245
-
389
+ </div>
390
+
391
+ </div>
246
392
 
247
393
  <% end %>
248
394
 
249
395
 
250
396
 
251
-
397
+ <div class="form-group row">
398
+
252
-
399
+ <label for="inputPassword3" class="col-sm-3 col-form-label"></label>
400
+
401
+ <div class="col-sm-9 text-center">
402
+
253
- <%= f.button :submit, "Send", class: "btn btn-primary" %>
403
+ <%= f.button :submit, (user.new_record? ? "Record" : "Update"), class: "btn btn-primary" %>
404
+
405
+ </div>
406
+
407
+ </div>
254
408
 
255
409
  <% end %>
256
410
 

9

欠けたコードの追加

2020/01/31 07:28

投稿

YousukeTanaka
YousukeTanaka

スコア79

test CHANGED
File without changes
test CHANGED
@@ -216,7 +216,7 @@
216
216
 
217
217
  ```
218
218
 
219
- <%= simple_form_for(user, url: user_profile_update_path(current_user), method: :put,
219
+ <%= simple_form_for(user, url: user_profile_update_path(current_user), method: :put, html:{ multipart: true }) do |f| %>
220
220
 
221
221
 
222
222
 

8

説明の変更

2020/01/31 07:26

投稿

YousukeTanaka
YousukeTanaka

スコア79

test CHANGED
File without changes
test CHANGED
@@ -220,7 +220,7 @@
220
220
 
221
221
 
222
222
 
223
- //親要素のカラム
223
+ //親テーブルの要素
224
224
 
225
225
  <%= f.input :fullname, label: false, input_html: { value: current_user.fullname, class: "form-control" }, required: true, autofocus:true %>
226
226
 
@@ -230,7 +230,7 @@
230
230
 
231
231
 
232
232
 
233
- //子要素のカラム=>以下要素見えない状況です。
233
+ //子テーブルの要素=>部分全て表示されない状況です。
234
234
 
235
235
  <%= f.simple_fields_for :student do |p| %>
236
236
 
@@ -258,12 +258,18 @@
258
258
 
259
259
 
260
260
 
261
- 上記の結果は、親テーブルの表示はできますが、子テーブルの表示ができない状況です。ただし、viewsの```ここに言語を入力
261
+ 上記の結果は、親テーブルの表示はできますが、子テーブルの表示ができない状況です。ただし、viewsの
262
+
263
+
264
+
265
+ ```
262
266
 
263
267
  <%= f.simple_fields_for :student do |p| %>
264
268
 
265
269
  ```
266
270
 
271
+
272
+
267
273
  のstudentを"students"に変えた場合は、子要素の部分が表示されます。ただし、保存ができません。私自身は、controllerの書き方に問題があるのではないかと考えていますが、色々と試してみましたが、解決に至っていません。お知恵をお貸しいただけると幸いです。
268
274
 
269
275
 

7

文字を編集

2020/01/31 07:11

投稿

YousukeTanaka
YousukeTanaka

スコア79

test CHANGED
File without changes
test CHANGED
@@ -214,7 +214,7 @@
214
214
 
215
215
  ---
216
216
 
217
- ```ここに言語を入力
217
+ ```
218
218
 
219
219
  <%= simple_form_for(user, url: user_profile_update_path(current_user), method: :put,
220
220
 

6

修正依頼者の指示にしたがい、情報を追加。

2020/01/31 07:08

投稿

YousukeTanaka
YousukeTanaka

スコア79

test CHANGED
File without changes
test CHANGED
@@ -64,6 +64,94 @@
64
64
 
65
65
 
66
66
 
67
+
68
+
69
+ Table構造
70
+
71
+ ---
72
+
73
+ ```ここに言語を入力
74
+
75
+ Usersテーブル
76
+
77
+
78
+
79
+ create_table "users", force: :cascade do |t|
80
+
81
+ t.string "email", default: "", null: false
82
+
83
+ t.string "encrypted_password", default: "", null: false
84
+
85
+ t.string "reset_password_token"
86
+
87
+ t.datetime "reset_password_sent_at"
88
+
89
+ t.datetime "remember_created_at"
90
+
91
+ t.datetime "created_at", null: false
92
+
93
+ t.datetime "updated_at", null: false
94
+
95
+ t.string "fullname"
96
+
97
+ t.integer "unread", default: 0
98
+
99
+ t.bigint "global_user_id"
100
+
101
+ t.bigint "school_person_in_charge_id"
102
+
103
+ t.bigint "student_id"
104
+
105
+ t.index ["email"], name: "index_users_on_email", unique: true
106
+
107
+ t.index ["global_user_id"], name: "index_users_on_global_user_id"
108
+
109
+ t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
110
+
111
+ t.index ["school_person_in_charge_id"], name: "index_users_on_school_person_in_charge_id"
112
+
113
+ t.index ["student_id"], name: "index_users_on_student_id"
114
+
115
+ end
116
+
117
+ ```
118
+
119
+
120
+
121
+
122
+
123
+ studentsテーブル
124
+
125
+
126
+
127
+ ```ここに言語を入力
128
+
129
+ create_table "students", force: :cascade do |t|
130
+
131
+ t.string "nickname"
132
+
133
+ t.date "birth"
134
+
135
+ t.integer "gender"
136
+
137
+ t.string "image"
138
+
139
+ t.text "comment"
140
+
141
+ t.bigint "user_id"
142
+
143
+ t.datetime "created_at", null: false
144
+
145
+ t.datetime "updated_at", null: false
146
+
147
+ t.index ["user_id"], name: "index_students_on_user_id"
148
+
149
+ end
150
+
151
+ ```
152
+
153
+
154
+
67
155
  Controllerの記載
68
156
 
69
157
  ---
@@ -128,145 +216,41 @@
128
216
 
129
217
  ```ここに言語を入力
130
218
 
131
- <%= simple_form_for(user, url: user_profile_update_path(current_user), method: :put, html:{ multipart: true }) do |f| %>
219
+ <%= simple_form_for(user, url: user_profile_update_path(current_user), method: :put,
132
-
133
- <%= f.error_notification %>
220
+
134
-
135
- <%= f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present? %>
221
+
136
-
137
-
138
-
139
- <div class="form-group row">
222
+
140
-
141
- <label for="inputEmail3" class="col-sm-3 col-form-label">Fullname</label>
142
-
143
- <div class="col-sm-9">
223
+ //親要素のカラム
144
224
 
145
225
  <%= f.input :fullname, label: false, input_html: { value: current_user.fullname, class: "form-control" }, required: true, autofocus:true %>
146
226
 
147
- </div>
148
-
149
- </div>
150
-
151
- <div class="form-group row">
152
-
153
- <label for="inputEmail3" class="col-sm-3 col-form-label">Email</label>
154
-
155
- <div class="col-sm-9">
156
-
157
- <%= f.input :email, label: false, input_html: { value: current_user.email, class: "form-control"}, required: true, autofocus: true %>
158
-
159
- </div>
160
-
161
- </div>
162
-
163
227
 
164
228
 
165
229
 
166
230
 
231
+
232
+
233
+ //子要素のカラム=>以下の要素が見えない状況です。
234
+
167
235
  <%= f.simple_fields_for :student do |p| %>
168
236
 
169
- <div class="form-group row">
237
+
170
-
171
- <label for="inputPassword3" class="col-sm-3 col-form-label">Nickname</label>
172
-
173
- <div class="col-sm-9">
174
238
 
175
239
  <%= p.input :nickname, label: false, required: true, autofocus: true, input_html: { class: "form-control"}, wrapper: false, label_html: { class: "label" } %>
176
240
 
177
- </div>
241
+
178
-
179
- </div>
180
-
181
- <div class="form-group row">
182
-
183
- <label for="inputPassword3" class="col-sm-3 col-form-label">Birthday</label>
184
-
185
- <div class="col-sm-9 d-flex flex-row justify-content-between align-items-center">
186
-
187
- <%= p.input :birth,
188
-
189
- label: false,
190
-
191
- required: true,
192
-
193
- input_html: { class: "form-control mx-1"},
194
-
195
- wrapper: false,
196
-
197
- as: :date,
198
-
199
- start_year: Date.today.year - 60,
200
-
201
- end_year: Date.today.year - 6, discard_day: true,
202
-
203
- order: [:month, :year] %>
204
-
205
- </div>
206
-
207
- </div>
208
-
209
- <fieldset class="form-group">
210
-
211
- <div class="row">
212
-
213
- <legend class="col-form-label col-sm-3 pt-0">Gender</legend>
214
-
215
- <div class="col-sm-9">
216
-
217
- <div class="form-check">
218
-
219
- <%= p.input :gender,
220
-
221
- :label => false,
222
-
223
- :collection => [[0, 'Male'], [1, 'Female']],
224
-
225
- :label_method => :last,
226
-
227
- :value_method => :first,
228
-
229
- :item_wrapper_class => 'inline',
230
-
231
- :input_html => { class: "form-check-input" },
232
-
233
- :as => :radio_buttons %>
234
-
235
- </div>
236
-
237
- </div>
238
-
239
- </div>
240
-
241
- </fieldset>
242
-
243
- <div class="form-group row">
244
-
245
- <label for="inputPassword3" class="col-sm-3 col-form-label">Self Introduction</label>
246
-
247
- <div class="col-sm-9">
248
242
 
249
243
  <%= p.input :comment, label: false, as: :text, required: true, autofocus: true, input_html: { class: "form-control", rows: 7}, wrapper: false, label_html: { class: "label" } %>
250
244
 
251
- </div>
245
+
252
-
253
- </div>
254
246
 
255
247
  <% end %>
256
248
 
257
249
 
258
250
 
259
- <div class="form-group row">
251
+
260
-
261
- <label for="inputPassword3" class="col-sm-3 col-form-label"></label>
252
+
262
-
263
- <div class="col-sm-9 text-center">
264
-
265
- <%= f.button :submit, (user.new_record? ? "Record" : "Update"), class: "btn btn-primary" %>
253
+ <%= f.button :submit, "Send", class: "btn btn-primary" %>
266
-
267
- </div>
268
-
269
- </div>
270
254
 
271
255
  <% end %>
272
256
 
@@ -274,9 +258,17 @@
274
258
 
275
259
 
276
260
 
277
- 上記の結果は、親テーブルの表示はできますが、子テーブルの表示ができない状況です。
261
+ 上記の結果は、親テーブルの表示はできますが、子テーブルの表示ができない状況です。ただし、viewsの```ここに言語を入力
262
+
278
-
263
+ <%= f.simple_fields_for :student do |p| %>
264
+
265
+ ```
266
+
279
- 私自身は、controllerの書き方に問題があるのではないかと考えていますが、色々と試してみましたが、解決に至っていません。お知恵をお貸しいただけると幸いです。
267
+ のstudentを"students"に変えた場合は、子要素の部分が表示されます。ただし、保存ができません。私自身は、controllerの書き方に問題があるのではないかと考えていますが、色々と試してみましたが、解決に至っていません。お知恵をお貸しいただけると幸いです。
268
+
269
+
270
+
271
+
280
272
 
281
273
 
282
274
 

5

追加説明

2020/01/31 07:08

投稿

YousukeTanaka
YousukeTanaka

スコア79

test CHANGED
File without changes
test CHANGED
@@ -12,7 +12,7 @@
12
12
 
13
13
  ---
14
14
 
15
- 以下、2点を解決い。
15
+ 以下、2点の問題が発生ます
16
16
 
17
17
  ①Studentの入力部分が非表示になっている。
18
18
 
@@ -20,6 +20,10 @@
20
20
 
21
21
 
22
22
 
23
+ そのために、Controller部分を確認し、フィードバックをいただけないでしょうか?
24
+
25
+
26
+
23
27
  ![イメージ説明](f19c10838c3bbadc3f5b9c75d42c5a4e.png)
24
28
 
25
29
 

4

コードの修正

2020/01/27 15:33

投稿

YousukeTanaka
YousukeTanaka

スコア79

test CHANGED
File without changes
test CHANGED
@@ -124,7 +124,7 @@
124
124
 
125
125
  ```ここに言語を入力
126
126
 
127
- <%= simple_form_for(user, url: user_profile_update_path(user), method: :put, html:{ multipart: true }) do |f| %>
127
+ <%= simple_form_for(user, url: user_profile_update_path(current_user), method: :put, html:{ multipart: true }) do |f| %>
128
128
 
129
129
  <%= f.error_notification %>
130
130
 

3

文字の訂正

2020/01/27 06:54

投稿

YousukeTanaka
YousukeTanaka

スコア79

test CHANGED
File without changes
test CHANGED
@@ -14,7 +14,7 @@
14
14
 
15
15
  以下、2点を解決したい。
16
16
 
17
- ①Studentの入力フォームが非表示になっている。
17
+ ①Studentの入力部分が非表示になっている。
18
18
 
19
19
  ②以下のエラーが発生している。
20
20
 

2

補足情報の追加

2020/01/27 06:45

投稿

YousukeTanaka
YousukeTanaka

スコア79

test CHANGED
File without changes
test CHANGED
@@ -285,3 +285,5 @@
285
285
  Rails 6.0.2.1
286
286
 
287
287
  Deviseというgemを使って、User管理を行なっています。
288
+
289
+ form は、simple_formというgemを使っています。

1

補足情報の追加

2020/01/27 06:45

投稿

YousukeTanaka
YousukeTanaka

スコア79

test CHANGED
File without changes
test CHANGED
@@ -273,3 +273,15 @@
273
273
  上記の結果は、親テーブルの表示はできますが、子テーブルの表示ができない状況です。
274
274
 
275
275
  私自身は、controllerの書き方に問題があるのではないかと考えていますが、色々と試してみましたが、解決に至っていません。お知恵をお貸しいただけると幸いです。
276
+
277
+
278
+
279
+ 補足情報
280
+
281
+ ---
282
+
283
+ ruby 2.5.7p206
284
+
285
+ Rails 6.0.2.1
286
+
287
+ Deviseというgemを使って、User管理を行なっています。