teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

3

パイプラインの件

2021/03/29 09:29

投稿

FKM
FKM

スコア3662

title CHANGED
File without changes
body CHANGED
@@ -238,4 +238,6 @@
238
238
  #yarn add jquery bootstrap popper.js
239
239
  ```
240
240
 
241
- applicaton.html.erbファイルで色々付けたり消したりもしましたが、結局解決方法がわからずじまいです。ご教示よろしくお願い致します。
241
+ applicaton.html.erbファイルで色々付けたり消したりもしましたが、結局解決方法がわからずじまいです。ご教示よろしくお願い致します。
242
+
243
+ なお、以前はbootstrapもAjaxも正常に起動していましたが、バックアップファイルを確認したところ、Assetsパイプラインとwebpackがグチャグチャになっていたため、再現できませんでした(Railsも以前は6.0.3で動いていました)。

2

制御ファイルについて

2021/03/29 09:28

投稿

FKM
FKM

スコア3662

title CHANGED
File without changes
body CHANGED
@@ -71,6 +71,165 @@
71
71
  @import '~bootstrap/scss/bootstrap';
72
72
  ```
73
73
 
74
+ #制御にかかわるファイル
75
+ 指摘がございましたので、制御にかかわるファイル(テンプレート、コントローラ、スクリプト)を記載しました。
76
+
77
+ テンプレート
78
+
79
+ index.html.erb
80
+ ```erb
81
+ <%- model_class = City -%>
82
+
83
+ <div class="panel panel-default" id="list">
84
+ <div class="panel-heading">
85
+ <div class="panel-title">検索</div>
86
+ </div>
87
+ <div class="panel-body" id="ajax-contents">
88
+ <%= search_form_for(@q , :id=>'city-form', :method=> 'get',:remote => true) do |f| %>
89
+ <div class="row">
90
+ <!-- 地方の選択 -->
91
+ <div class="col-sm-12">
92
+ <%= f.collection_check_boxes(:region_in,@regions, :region, :region,include_hidden: false) do |b| %>
93
+ <label class="checkbox-inline">
94
+ <%= b.check_box class:"form-control2" do %>
95
+ <%= b.check_box + b.text %>
96
+     <% end %>
97
+ <%= b.label {b.text} %>
98
+ </label>
99
+ <% end %>
100
+ </div>
101
+ <!-- 都道府県名の完全一致検索 -->
102
+ <div class="col-sm-6">
103
+
104
+ <div class="form-group">
105
+ <%= f.label :pref_no_eq %>
106
+
107
+ <%= f.select :pref_no_eq,Pref::PREF.to_a,{},{class:'form-control'} %>
108
+ </div>
109
+ </div>
110
+
111
+ <!-- 市名の部分一致検索 -->
112
+ <div class="col-sm-4">
113
+ <div class="form-group">
114
+ <%= f.label :city_name_cont %>
115
+ <%= f.text_field :city_name_cont, class: "form-control", placeholder: "部分一致" %>
116
+ </div>
117
+ </div>
118
+ </div><!-- @row -->
119
+
120
+ <div class="row">
121
+ <!-- 人口の範囲検索 -->
122
+ <div class="form-group">
123
+ <div class="col-sm-12 form-inline">
124
+ <%= f.label :'人口の範囲検索' %>
125
+ <%= f.search_field :population_gteq, class: "form-control", placeholder: "最低値" %>
126
+
127
+ <%= f.search_field :population_lteq, class: "form-control", placeholder: "最高値" %>
128
+ <%= f.submit class: "btn btn-primary btn-search", id: "sbm" %>
129
+ <%= link_to 'クリア', url_for, class: "btn btn-default" %>
130
+ <%= link_to t('.new', :default => t("helpers.links.new")),new_city_path,:class => 'btn btn-primary' %>
131
+ </div>
132
+ </div>
133
+ </div><!-- @row -->
134
+ <% end %>
135
+ <div>
136
+ </div>
137
+
138
+ <table class="table table-striped" id="tbl">
139
+ <thead>
140
+ <tr>
141
+ <th><%= model_class.human_attribute_name(:id) %></th>
142
+ <th><%= model_class.human_attribute_name(:base_no) %></th>
143
+ <th><%= model_class.human_attribute_name(:city_name) %></th>
144
+ <th><%= model_class.human_attribute_name(:pref_no) %></th>
145
+ <th><%= model_class.human_attribute_name(:population) %></th>
146
+ <th><%=t '.actions', :default => t("helpers.actions") %></th>
147
+ </tr>
148
+ </thead>
149
+ <tbody id="ajax-response-wrapper">
150
+ <%= render 'ajax_container' %>
151
+ </tbody>
152
+ </table>
153
+ <div id="pager"><%= render 'ajax_pager' %></div>
154
+ <%= javascript_pack_tag 'ajax_controll' %>
155
+ <script type="text/javascript">
156
+ register_callback();
157
+ </script>
158
+
159
+ ```
160
+
161
+ コントローラ(一部抜粋)
162
+
163
+ ```erb
164
+ def index
165
+ query = "select distinct(region) as region from cities group by region order by pref_no"
166
+ @regions = City.find_by_sql(query)
167
+ unless params[:q].blank?
168
+ logger.debug('TR')
169
+ @q = City.ransack(params[:q])
170
+ @q.sorts = 'population desc' if @q.sorts.empty?
171
+ @cities = @q.result.page(params[:page]).per(10)
172
+ #コンテナのレンダリング
173
+ p_cities = render_to_string(
174
+ partial: 'ajax_container',
175
+ locals: { :cities => @cities},
176
+ )
177
+ #ページャーのレンダリング
178
+ p_pager = render_to_string(
179
+ partial: 'ajax_pager',
180
+ locals: { :cities => @cities },
181
+ remote: true
182
+ )
183
+ if request.xhr?
184
+ logger.debug("Ajax成功!")
185
+ render partial: "ajax_container",
186
+ locals:
187
+ {
188
+ container: p_cities,
189
+ pager: p_pager,
190
+ }
191
+ end
192
+ else
193
+ @q = City.ransack(params[:q])
194
+ @q.sorts = 'population desc' if @q.sorts.empty?
195
+ @cities = @q.result.page(params[:page]).per(10)
196
+ end
197
+ end
198
+
199
+ ```
200
+
201
+ ajaxの制御用スクリプト
202
+ app/javascript/packs/ajax_controll.js
203
+
204
+ ```js
205
+ import * as $ from "jquery";
206
+
207
+ function register_callback(){
208
+ jQuery(function(){
209
+ $(".form-control,.form-control2").each(function(){
210
+ $(this).on('change focusout',function(){
211
+ $('#sbm').click();
212
+ })
213
+ })
214
+ $(document).bind(
215
+ "ready ajaxComplete",
216
+ "#city-form",
217
+ function(e,d){
218
+ data = d.detail[0]
219
+ alert(data)
220
+ $('#ajax-response-wrapper').empty().append(data.container)
221
+ $('#pager').empty().append(data.pager)
222
+ }
223
+ )
224
+ $("#city-form").on("ajax:fail",function(event,data,status,xhr){
225
+ alert("fail!")
226
+ })
227
+ })
228
+ }
229
+
230
+ window.register_callback = register_callback;
231
+ ```
232
+
74
233
  #やったこと
75
234
  webpackの再インストールやyarnの繰り返し
76
235
  ```

1

スペック

2021/03/29 09:22

投稿

FKM
FKM

スコア3662

title CHANGED
File without changes
body CHANGED
@@ -1,4 +1,8 @@
1
- CentOS7.3Rails6で作っていたシステムが破損したので、再度作り直してみたところ、困った現象が発生しています。
1
+ CentOS7.3内にRails6で作っていたシステムが破損したので、再度作り直してみたところ、困った現象が発生しています。
2
+
3
+ - Ruby 2.6.6
4
+ - Rails6.1.3.1
5
+ - Apache 2.4.46
2
6
 
3
7
  # 発生している問題
4
8
  - Ajaxは動作しているが、Bootstrapは機能していない