質問編集履歴

3

パイプラインの件

2021/03/29 09:29

投稿

FKM
FKM

スコア3640

test CHANGED
File without changes
test CHANGED
@@ -479,3 +479,7 @@
479
479
 
480
480
 
481
481
  applicaton.html.erbファイルで色々付けたり消したりもしましたが、結局解決方法がわからずじまいです。ご教示よろしくお願い致します。
482
+
483
+
484
+
485
+ なお、以前はbootstrapもAjaxも正常に起動していましたが、バックアップファイルを確認したところ、Assetsパイプラインとwebpackがグチャグチャになっていたため、再現できませんでした(Railsも以前は6.0.3で動いていました)。

2

制御ファイルについて

2021/03/29 09:28

投稿

FKM
FKM

スコア3640

test CHANGED
File without changes
test CHANGED
@@ -144,6 +144,324 @@
144
144
 
145
145
 
146
146
 
147
+ #制御にかかわるファイル
148
+
149
+ 指摘がございましたので、制御にかかわるファイル(テンプレート、コントローラ、スクリプト)を記載しました。
150
+
151
+
152
+
153
+ テンプレート
154
+
155
+
156
+
157
+ index.html.erb
158
+
159
+ ```erb
160
+
161
+ <%- model_class = City -%>
162
+
163
+
164
+
165
+ <div class="panel panel-default" id="list">
166
+
167
+ <div class="panel-heading">
168
+
169
+ <div class="panel-title">検索</div>
170
+
171
+ </div>
172
+
173
+ <div class="panel-body" id="ajax-contents">
174
+
175
+ <%= search_form_for(@q , :id=>'city-form', :method=> 'get',:remote => true) do |f| %>
176
+
177
+ <div class="row">
178
+
179
+ <!-- 地方の選択 -->
180
+
181
+ <div class="col-sm-12">
182
+
183
+ <%= f.collection_check_boxes(:region_in,@regions, :region, :region,include_hidden: false) do |b| %>
184
+
185
+ <label class="checkbox-inline">
186
+
187
+ <%= b.check_box class:"form-control2" do %>
188
+
189
+ <%= b.check_box + b.text %>
190
+
191
+     <% end %>
192
+
193
+ <%= b.label {b.text} %>
194
+
195
+ </label>
196
+
197
+ <% end %>
198
+
199
+ </div>
200
+
201
+ <!-- 都道府県名の完全一致検索 -->
202
+
203
+ <div class="col-sm-6">
204
+
205
+
206
+
207
+ <div class="form-group">
208
+
209
+ <%= f.label :pref_no_eq %>
210
+
211
+
212
+
213
+ <%= f.select :pref_no_eq,Pref::PREF.to_a,{},{class:'form-control'} %>
214
+
215
+ </div>
216
+
217
+ </div>
218
+
219
+
220
+
221
+ <!-- 市名の部分一致検索 -->
222
+
223
+ <div class="col-sm-4">
224
+
225
+ <div class="form-group">
226
+
227
+ <%= f.label :city_name_cont %>
228
+
229
+ <%= f.text_field :city_name_cont, class: "form-control", placeholder: "部分一致" %>
230
+
231
+ </div>
232
+
233
+ </div>
234
+
235
+ </div><!-- @row -->
236
+
237
+
238
+
239
+ <div class="row">
240
+
241
+ <!-- 人口の範囲検索 -->
242
+
243
+ <div class="form-group">
244
+
245
+ <div class="col-sm-12 form-inline">
246
+
247
+ <%= f.label :'人口の範囲検索' %>
248
+
249
+ <%= f.search_field :population_gteq, class: "form-control", placeholder: "最低値" %>
250
+
251
+
252
+
253
+ <%= f.search_field :population_lteq, class: "form-control", placeholder: "最高値" %>
254
+
255
+ <%= f.submit class: "btn btn-primary btn-search", id: "sbm" %>
256
+
257
+ <%= link_to 'クリア', url_for, class: "btn btn-default" %>
258
+
259
+ <%= link_to t('.new', :default => t("helpers.links.new")),new_city_path,:class => 'btn btn-primary' %>
260
+
261
+ </div>
262
+
263
+ </div>
264
+
265
+ </div><!-- @row -->
266
+
267
+ <% end %>
268
+
269
+ <div>
270
+
271
+ </div>
272
+
273
+
274
+
275
+ <table class="table table-striped" id="tbl">
276
+
277
+ <thead>
278
+
279
+ <tr>
280
+
281
+ <th><%= model_class.human_attribute_name(:id) %></th>
282
+
283
+ <th><%= model_class.human_attribute_name(:base_no) %></th>
284
+
285
+ <th><%= model_class.human_attribute_name(:city_name) %></th>
286
+
287
+ <th><%= model_class.human_attribute_name(:pref_no) %></th>
288
+
289
+ <th><%= model_class.human_attribute_name(:population) %></th>
290
+
291
+ <th><%=t '.actions', :default => t("helpers.actions") %></th>
292
+
293
+ </tr>
294
+
295
+ </thead>
296
+
297
+ <tbody id="ajax-response-wrapper">
298
+
299
+ <%= render 'ajax_container' %>
300
+
301
+ </tbody>
302
+
303
+ </table>
304
+
305
+ <div id="pager"><%= render 'ajax_pager' %></div>
306
+
307
+ <%= javascript_pack_tag 'ajax_controll' %>
308
+
309
+ <script type="text/javascript">
310
+
311
+ register_callback();
312
+
313
+ </script>
314
+
315
+
316
+
317
+ ```
318
+
319
+
320
+
321
+ コントローラ(一部抜粋)
322
+
323
+
324
+
325
+ ```erb
326
+
327
+ def index
328
+
329
+ query = "select distinct(region) as region from cities group by region order by pref_no"
330
+
331
+ @regions = City.find_by_sql(query)
332
+
333
+ unless params[:q].blank?
334
+
335
+ logger.debug('TR')
336
+
337
+ @q = City.ransack(params[:q])
338
+
339
+ @q.sorts = 'population desc' if @q.sorts.empty?
340
+
341
+ @cities = @q.result.page(params[:page]).per(10)
342
+
343
+ #コンテナのレンダリング
344
+
345
+ p_cities = render_to_string(
346
+
347
+ partial: 'ajax_container',
348
+
349
+ locals: { :cities => @cities},
350
+
351
+ )
352
+
353
+ #ページャーのレンダリング
354
+
355
+ p_pager = render_to_string(
356
+
357
+ partial: 'ajax_pager',
358
+
359
+ locals: { :cities => @cities },
360
+
361
+ remote: true
362
+
363
+ )
364
+
365
+ if request.xhr?
366
+
367
+ logger.debug("Ajax成功!")
368
+
369
+ render partial: "ajax_container",
370
+
371
+ locals:
372
+
373
+ {
374
+
375
+ container: p_cities,
376
+
377
+ pager: p_pager,
378
+
379
+ }
380
+
381
+ end
382
+
383
+ else
384
+
385
+ @q = City.ransack(params[:q])
386
+
387
+ @q.sorts = 'population desc' if @q.sorts.empty?
388
+
389
+ @cities = @q.result.page(params[:page]).per(10)
390
+
391
+ end
392
+
393
+ end
394
+
395
+
396
+
397
+ ```
398
+
399
+
400
+
401
+ ajaxの制御用スクリプト
402
+
403
+ app/javascript/packs/ajax_controll.js
404
+
405
+
406
+
407
+ ```js
408
+
409
+ import * as $ from "jquery";
410
+
411
+
412
+
413
+ function register_callback(){
414
+
415
+ jQuery(function(){
416
+
417
+ $(".form-control,.form-control2").each(function(){
418
+
419
+ $(this).on('change focusout',function(){
420
+
421
+ $('#sbm').click();
422
+
423
+ })
424
+
425
+ })
426
+
427
+ $(document).bind(
428
+
429
+ "ready ajaxComplete",
430
+
431
+ "#city-form",
432
+
433
+ function(e,d){
434
+
435
+ data = d.detail[0]
436
+
437
+ alert(data)
438
+
439
+ $('#ajax-response-wrapper').empty().append(data.container)
440
+
441
+ $('#pager').empty().append(data.pager)
442
+
443
+ }
444
+
445
+ )
446
+
447
+ $("#city-form").on("ajax:fail",function(event,data,status,xhr){
448
+
449
+ alert("fail!")
450
+
451
+ })
452
+
453
+ })
454
+
455
+ }
456
+
457
+
458
+
459
+ window.register_callback = register_callback;
460
+
461
+ ```
462
+
463
+
464
+
147
465
  #やったこと
148
466
 
149
467
  webpackの再インストールやyarnの繰り返し

1

スペック

2021/03/29 09:22

投稿

FKM
FKM

スコア3640

test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,12 @@
1
- CentOS7.3Rails6で作っていたシステムが破損したので、再度作り直してみたところ、困った現象が発生しています。
1
+ CentOS7.3内にRails6で作っていたシステムが破損したので、再度作り直してみたところ、困った現象が発生しています。
2
+
3
+
4
+
5
+ - Ruby 2.6.6
6
+
7
+ - Rails6.1.3.1
8
+
9
+ - Apache 2.4.46
2
10
 
3
11
 
4
12