質問編集履歴

2

修正

2019/08/22 06:11

投稿

ikt_erk122
ikt_erk122

スコア40

test CHANGED
File without changes
test CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  <困っていること>
8
8
 
9
- 正しい情報での更新はできるのですが誤った情報だとエラーメッセージは表示されないし何も変わらない。
9
+ 正しい情報での更新はできるのですが誤った情報だとエラーメッセージは表示されずエラーに
10
10
 
11
11
 
12
12
 
@@ -54,10 +54,12 @@
54
54
 
55
55
  else
56
56
 
57
+ @users = User.paginate(page: params[:page])
58
+
59
+ flash[:danger] = "#{@user.name}さんの基本情報の更新に失敗しました。"
60
+
57
61
  render 'index'
58
62
 
59
- flash[:danger] = "更新に失敗しました。"
60
-
61
63
  end
62
64
 
63
65
  end
@@ -160,6 +162,26 @@
160
162
 
161
163
  <%= form_with model: user, url: update_basic_info_path(params: {id: user.id}), local: true, data: {remote: 'true'} do |f| %>
162
164
 
165
+
166
+
167
+ <% if user.errors.any? %>
168
+
169
+ <div class="alert alert-danger">
170
+
171
+ <ul>
172
+
173
+ <% user.errors.full_messages.each do |msg| %>
174
+
175
+ <li><%= msg %></li>
176
+
177
+ <% end %>
178
+
179
+ </ul>
180
+
181
+ </div>
182
+
183
+ <% end %>
184
+
163
185
 
164
186
 
165
187
  <%= f.label :name %>
@@ -246,7 +268,9 @@
246
268
 
247
269
  delete '/logout', to: 'sessions#destroy'
248
270
 
271
+ # get '/edit-basic-info/:id', to: 'users#edit_basic_info', as: :basic_info
272
+
249
- patch 'update-basic-info', to: 'users#update_basic_info'
273
+ #patch 'update-basic-info', to: 'users#update_basic_info'
250
274
 
251
275
  get 'users/:id/attendances/:date/edit', to: 'attendances#edit', as: :edit_attendances
252
276
 
@@ -254,6 +278,12 @@
254
278
 
255
279
  resources :users do
256
280
 
281
+ member do
282
+
283
+ patch 'update_basic_info'
284
+
285
+ end
286
+
257
287
  resources :attendances, only: :create
258
288
 
259
289
  end
@@ -304,36 +334,8 @@
304
334
 
305
335
  ```
306
336
 
307
- user.rb
337
+
308
-
309
- ```ここに言語を入力
338
+
310
-
311
- class User < ApplicationRecord
339
+
312
-
313
- attr_accessor :remember_token
340
+
314
-
315
- has_many :attendances, dependent: :destroy
316
-
317
- before_save { self.email = email.downcase }
318
-
319
- validates :name, presence: true, length: { maximum: 50 }
320
-
321
- VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+.[a-z]+\z/i
322
-
323
- validates :email, presence: true, length: { maximum: 255 },
324
-
325
- format: { with: VALID_EMAIL_REGEX },
326
-
327
- uniqueness: { case_sensitive: false }
328
-
329
- has_secure_password
330
-
331
- validates :password, presence: true, length: { minimum: 6 }, allow_nil: true
332
-
333
- validates :department, length: { in: 2..50 }, allow_blank: true
334
-
335
- ```
336
-
337
- 検証
338
-
339
- ![イメージ説明](47d65db91e2b5402ca668b2e419be969.jpeg)
341
+ ![イメージ説明](6cb3dc065ea38872346a7ec78c4b793b.jpeg)

1

修正

2019/08/22 06:10

投稿

ikt_erk122
ikt_erk122

スコア40

test CHANGED
File without changes
test CHANGED
@@ -264,6 +264,76 @@
264
264
 
265
265
  ```
266
266
 
267
+ schema.rb
268
+
269
+ ```ここに言語を入力
270
+
271
+ create_table "users", force: :cascade do |t|
272
+
273
+ t.string "name"
274
+
275
+ t.string "email"
276
+
277
+ t.datetime "created_at", null: false
278
+
279
+ t.datetime "updated_at", null: false
280
+
281
+ t.string "password_digest"
282
+
283
+ t.boolean "admin", default: false
284
+
285
+ t.string "department"
286
+
287
+ t.datetime "basic_time", default: "2019-02-19 22:30:00"
288
+
289
+ t.datetime "work_time", default: "2019-02-19 23:00:00"
290
+
291
+ t.string "remember_digest"
292
+
293
+ t.datetime "work_end_time", default: "2019-02-20 08:00:00"
294
+
295
+ t.string "employee_number"
296
+
297
+ t.string "uid"
298
+
299
+ t.boolean "superior", default: false
300
+
301
+ t.index ["email"], name: "index_users_on_email", unique: true
302
+
303
+ end
304
+
305
+ ```
306
+
307
+ user.rb
308
+
309
+ ```ここに言語を入力
310
+
311
+ class User < ApplicationRecord
312
+
313
+ attr_accessor :remember_token
314
+
315
+ has_many :attendances, dependent: :destroy
316
+
317
+ before_save { self.email = email.downcase }
318
+
319
+ validates :name, presence: true, length: { maximum: 50 }
320
+
321
+ VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+.[a-z]+\z/i
322
+
323
+ validates :email, presence: true, length: { maximum: 255 },
324
+
325
+ format: { with: VALID_EMAIL_REGEX },
326
+
327
+ uniqueness: { case_sensitive: false }
328
+
329
+ has_secure_password
330
+
331
+ validates :password, presence: true, length: { minimum: 6 }, allow_nil: true
332
+
333
+ validates :department, length: { in: 2..50 }, allow_blank: true
334
+
335
+ ```
336
+
267
337
  検証
268
338
 
269
339
  ![イメージ説明](47d65db91e2b5402ca668b2e419be969.jpeg)