質問編集履歴

3

コマンドで取得出来た情報:追加

2017/02/16 08:35

投稿

AkiraKan
AkiraKan

スコア12

test CHANGED
File without changes
test CHANGED
@@ -251,3 +251,33 @@
251
251
  end
252
252
 
253
253
  ```
254
+
255
+
256
+
257
+ コマンドで取得出来た情報:
258
+
259
+ ```
260
+
261
+ #<ActiveModel::Errors:0x89dc7f8
262
+
263
+ @base=
264
+
265
+ #<HourlyPay:0x8a74c88
266
+
267
+ id: nil,
268
+
269
+ tester_id: "905773432",
270
+
271
+ user_id: "118",
272
+
273
+ update_date: nil,
274
+
275
+ amount: nil,
276
+
277
+ created_at: nil,
278
+
279
+ updated_at: nil>,
280
+
281
+ @messages={:時給=>["を入力してください。"], :日付=>["を入力してください。"]}>
282
+
283
+ ```

2

FULLコードをアップ

2017/02/16 08:35

投稿

AkiraKan
AkiraKan

スコア12

test CHANGED
File without changes
test CHANGED
@@ -172,7 +172,7 @@
172
172
 
173
173
  ```
174
174
 
175
- def update
175
+ def update
176
176
 
177
177
  respond_to do |format|
178
178
 
@@ -180,7 +180,31 @@
180
180
 
181
181
  format.html do
182
182
 
183
+ if params[:update_password]
184
+
185
+ str_array = ('a'..'z').to_a + ('A'..'Z').to_a + ('0'..'9').to_a
186
+
187
+ password = ( Array.new(8){ str_array[rand(str_array.size)] } ).join
188
+
189
+ @tester.password = password
190
+
191
+ @tester.crypt_password
192
+
193
+ @tester.save
194
+
195
+ flash[:password]=password
196
+
197
+ # redirect_to action: 'show'
198
+
199
+ redirect_to action: 'show' and return # and return を書かないとエラーになる
200
+
201
+ elsif params[:delete_hourly_pay]
202
+
203
+ @user = HourlyPay.find(params[:tester][:hourlypay_id]).destroy
204
+
205
+ redirect_to action: 'edit', id: params[:tester][:tester_id]
206
+
183
- if params[:new_hourly_pay]
207
+ elsif params[:new_hourly_pay]
184
208
 
185
209
  @update_date_hourlypay = params[:new_updatedate]
186
210
 
@@ -200,28 +224,16 @@
200
224
 
201
225
  @hourlypay.save
202
226
 
203
- pp @tester.errors
204
-
205
- pp @hourlypay.errors
206
-
207
- if !@hourlypay.errors.empty?
208
-
209
- pp "ERRORS ======================>"
210
-
211
- render action: 'edit', id: @tester.id, :json => @hourlypay.errors
212
-
213
- else
214
-
215
- redirect_to action: 'edit', id: params[:tester][:tester_id]
216
-
217
- end
218
-
219
- else
220
-
221
- redirect_to action: 'index', page: @tester.calc_page
222
-
223
227
  end
224
228
 
229
+ pp "ERRORS ======================>"
230
+
231
+ pp @tester.errors
232
+
233
+ pp @hourlypay.errors
234
+
235
+ render :edit
236
+
225
237
  end
226
238
 
227
239
  format.json { render :show, status: :ok, location: @tester }

1

コントローラ修正

2017/02/16 08:20

投稿

AkiraKan
AkiraKan

スコア12

test CHANGED
File without changes
test CHANGED
@@ -176,6 +176,8 @@
176
176
 
177
177
  respond_to do |format|
178
178
 
179
+ if @tester.update(tester_params)
180
+
179
181
  format.html do
180
182
 
181
183
  if params[:new_hourly_pay]
@@ -204,17 +206,19 @@
204
206
 
205
207
  if !@hourlypay.errors.empty?
206
208
 
209
+ pp "ERRORS ======================>"
210
+
207
- render action: 'testers#edit', id: @tester.id, :json => @hourlypay.errors
211
+ render action: 'edit', id: @tester.id, :json => @hourlypay.errors
208
212
 
209
213
  else
210
214
 
211
- redirect_to action: 'edit', id: params[:tester][:tester_id]
215
+ redirect_to action: 'edit', id: params[:tester][:tester_id]
212
216
 
213
217
  end
214
218
 
215
219
  else
216
220
 
217
- render action: 'index', page: @tester.calc_page
221
+ redirect_to action: 'index', page: @tester.calc_page
218
222
 
219
223
  end
220
224
 
@@ -222,8 +226,16 @@
222
226
 
223
227
  format.json { render :show, status: :ok, location: @tester }
224
228
 
229
+ else
230
+
231
+ format.html { render :edit }
232
+
233
+ format.json { render json: @tester.errors, status: :unprocessable_entity }
234
+
235
+ end
236
+
225
237
  end
226
238
 
227
- end
239
+ end
228
-
240
+
229
- ```
241
+ ```