質問編集履歴

2

試行結果と追記

2021/02/17 13:23

投稿

taba.3011
taba.3011

スコア12

test CHANGED
File without changes
test CHANGED
@@ -32,326 +32,258 @@
32
32
 
33
33
  ### 該当のソースコード
34
34
 
35
- ####Gemfile
36
-
37
- ```
38
-
39
- gem 'bootstrap-sass', '~> 3.3.6'
40
-
41
- gem 'jquery-rails'
42
-
43
- group :production, :staging do
44
-
45
- gem 'unicorn'
35
+ #####assets/stylesheets/application.scss
36
+
37
+ ```
38
+
39
+ 省略
40
+
41
+ * It is generally better to create a new file per style scope.
42
+
43
+ *
44
+
45
+
46
+
47
+ */
48
+
49
+ @import "articles";
50
+
51
+ @import "bootstrap-sprockets";
52
+
53
+ @import "bootstrap";
54
+
55
+ ```
56
+
57
+ #####config/environment/production.rb
58
+
59
+ ```
60
+
61
+ Rails.application.configure do
62
+
63
+ # Settings specified here will take precedence over those in config/application.rb.
64
+
65
+
66
+
67
+ # Code is not reloaded between requests.
68
+
69
+ config.cache_classes = true
70
+
71
+
72
+
73
+ # Eager load code on boot. This eager loads most of Rails and
74
+
75
+ # your application in memory, allowing both threaded web servers
76
+
77
+ # and those relying on copy on write to perform better.
78
+
79
+ # Rake tasks automatically ignore this option for performance.
80
+
81
+ config.eager_load = true
82
+
83
+
84
+
85
+ # Full error reports are disabled and caching is turned on.
86
+
87
+ config.consider_all_requests_local = false
88
+
89
+ config.action_controller.perform_caching = true
90
+
91
+
92
+
93
+ # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"]
94
+
95
+ # or in config/master.key. This key is used to decrypt credentials (and other encrypted files).
96
+
97
+ # config.require_master_key = true
98
+
99
+
100
+
101
+ # Disable serving static files from the `/public` folder by default since
102
+
103
+ # Apache or NGINX already handles this.
104
+
105
+ config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
106
+
107
+
108
+
109
+ # Compress CSS using a preprocessor.
110
+
111
+ # config.assets.css_compressor = :sass
112
+
113
+
114
+
115
+ # Do not fallback to assets pipeline if a precompiled asset is missed.
116
+
117
+ config.assets.compile = ture
118
+
119
+
120
+
121
+ # Enable serving of images, stylesheets, and JavaScripts from an asset server.
122
+
123
+ # config.action_controller.asset_host = 'http://assets.example.com'
124
+
125
+
126
+
127
+ # Specifies the header that your server uses for sending files.
128
+
129
+ # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
130
+
131
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
132
+
133
+
134
+
135
+ # Store uploaded files on the local file system (see config/storage.yml for options).
136
+
137
+ config.active_storage.service = :local
138
+
139
+
140
+
141
+ # Mount Action Cable outside main process or domain.
142
+
143
+ # config.action_cable.mount_path = nil
144
+
145
+ # config.action_cable.url = 'wss://example.com/cable'
146
+
147
+ # config.action_cable.allowed_request_origins = [ 'http://example.com', /http://example.*/ ]
148
+
149
+
150
+
151
+ # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
152
+
153
+ # config.force_ssl = true
154
+
155
+
156
+
157
+ # Use the lowest log level to ensure availability of diagnostic information
158
+
159
+ # when problems arise.
160
+
161
+ config.log_level = :debug
162
+
163
+
164
+
165
+ # Prepend all log lines with the following tags.
166
+
167
+ config.log_tags = [ :request_id ]
168
+
169
+
170
+
171
+ # Use a different cache store in production.
172
+
173
+ # config.cache_store = :mem_cache_store
174
+
175
+
176
+
177
+ # Use a real queuing backend for Active Job (and separate queues per environment).
178
+
179
+ # config.active_job.queue_adapter = :resque
180
+
181
+ # config.active_job.queue_name_prefix = "stock_info_production"
182
+
183
+
184
+
185
+ config.action_mailer.perform_caching = false
186
+
187
+
188
+
189
+ # Ignore bad email addresses and do not raise email delivery errors.
190
+
191
+ # Set this to true and configure the email server for immediate delivery to raise delivery errors.
192
+
193
+ # config.action_mailer.raise_delivery_errors = false
194
+
195
+
196
+
197
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
198
+
199
+ # the I18n.default_locale when a translation cannot be found).
200
+
201
+ config.i18n.fallbacks = true
202
+
203
+
204
+
205
+ # Send deprecation notices to registered listeners.
206
+
207
+ config.active_support.deprecation = :notify
208
+
209
+
210
+
211
+ # Use default logging formatter so that PID and timestamp are not suppressed.
212
+
213
+ config.log_formatter = ::Logger::Formatter.new
214
+
215
+
216
+
217
+ # Use a different logger for distributed setups.
218
+
219
+ # require 'syslog/logger'
220
+
221
+ # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
222
+
223
+
224
+
225
+ if ENV["RAILS_LOG_TO_STDOUT"].present?
226
+
227
+ logger = ActiveSupport::Logger.new(STDOUT)
228
+
229
+ logger.formatter = config.log_formatter
230
+
231
+ config.logger = ActiveSupport::TaggedLogging.new(logger)
232
+
233
+ end
234
+
235
+
236
+
237
+ # Do not dump schema after migrations.
238
+
239
+ config.active_record.dump_schema_after_migration = false
240
+
241
+
242
+
243
+ # Inserts middleware to perform automatic connection switching.
244
+
245
+ # The `database_selector` hash is used to pass options to the DatabaseSelector
246
+
247
+ # middleware. The `delay` is used to determine how long to wait after a write
248
+
249
+ # to send a subsequent read to the primary.
250
+
251
+ #
252
+
253
+ # The `database_resolver` class is used by the middleware to determine which
254
+
255
+ # database is appropriate to use based on the time delay.
256
+
257
+ #
258
+
259
+ # The `database_resolver_context` class is used by the middleware to set
260
+
261
+ # timestamps for the last write to the primary. The resolver uses the context
262
+
263
+ # class timestamps to determine how long to wait before reading from the
264
+
265
+ # replica.
266
+
267
+ #
268
+
269
+ # By default Rails will store a last write timestamp in the session. The
270
+
271
+ # DatabaseSelector middleware is designed as such you can define your own
272
+
273
+ # strategy for connection switching and pass that into the middleware through
274
+
275
+ # these configuration options.
276
+
277
+ # config.active_record.database_selector = { delay: 2.seconds }
278
+
279
+ # config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver
280
+
281
+ # config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session
46
282
 
47
283
  end
48
284
 
49
285
  ```
50
286
 
51
- #####assets/stylesheets/application.scss
52
-
53
- ```
54
-
55
- 省略
56
-
57
- * It is generally better to create a new file per style scope.
58
-
59
- *
60
-
61
-
62
-
63
- */
64
-
65
- @import "articles";
66
-
67
- @import "bootstrap-sprockets";
68
-
69
- @import "bootstrap";
70
-
71
- ```
72
-
73
- #####javascript/src/application.scss
74
-
75
- ```
76
-
77
- @import "~@fortawesome/fontawesome-free/scss/fontawesome";
78
-
79
- ```
80
-
81
- #####javascript/packs/application.js
82
-
83
- ```
84
-
85
- // This file is automatically compiled by Webpack, along with any other files
86
-
87
- // present in this directory. You're encouraged to place your actual application logic in
88
-
89
- // a relevant structure within app/javascript and only use these pack files to reference
90
-
91
- // that code so it'll be compiled.
92
-
93
- require("@rails/ujs").start()
94
-
95
- // require("turbolinks").start()
96
-
97
- require("@rails/activestorage").start()
98
-
99
- require("channels")
100
-
101
- require("./preview")
102
-
103
- require("./count")
104
-
105
-
106
-
107
- // Uncomment to copy all static images under ../images to the output folder and reference
108
-
109
- // them with the image_pack_tag helper in views (e.g <%= image_pack_tag 'rails.png' %>)
110
-
111
- // or the `imagePath` JavaScript helper below.
112
-
113
- //
114
-
115
- // const images = require.context('../images', true)
116
-
117
- // const imagePath = (name) => images(name, true)
118
-
119
-
120
-
121
- import "@fortawesome/fontawesome-free/js/all"
122
-
123
- ```
124
-
125
- #####config/environment/production.rb
126
-
127
- ```
128
-
129
- Rails.application.configure do
130
-
131
- # Settings specified here will take precedence over those in config/application.rb.
132
-
133
-
134
-
135
- # Code is not reloaded between requests.
136
-
137
- config.cache_classes = true
138
-
139
-
140
-
141
- # Eager load code on boot. This eager loads most of Rails and
142
-
143
- # your application in memory, allowing both threaded web servers
144
-
145
- # and those relying on copy on write to perform better.
146
-
147
- # Rake tasks automatically ignore this option for performance.
148
-
149
- config.eager_load = true
150
-
151
-
152
-
153
- # Full error reports are disabled and caching is turned on.
154
-
155
- config.consider_all_requests_local = false
156
-
157
- config.action_controller.perform_caching = true
158
-
159
-
160
-
161
- # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"]
162
-
163
- # or in config/master.key. This key is used to decrypt credentials (and other encrypted files).
164
-
165
- # config.require_master_key = true
166
-
167
-
168
-
169
- # Disable serving static files from the `/public` folder by default since
170
-
171
- # Apache or NGINX already handles this.
172
-
173
- config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
174
-
175
-
176
-
177
- # Compress CSS using a preprocessor.
178
-
179
- # config.assets.css_compressor = :sass
180
-
181
-
182
-
183
- # Do not fallback to assets pipeline if a precompiled asset is missed.
184
-
185
- config.assets.compile = ture
186
-
187
-
188
-
189
- # Enable serving of images, stylesheets, and JavaScripts from an asset server.
190
-
191
- # config.action_controller.asset_host = 'http://assets.example.com'
192
-
193
-
194
-
195
- # Specifies the header that your server uses for sending files.
196
-
197
- # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
198
-
199
- # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
200
-
201
-
202
-
203
- # Store uploaded files on the local file system (see config/storage.yml for options).
204
-
205
- config.active_storage.service = :local
206
-
207
-
208
-
209
- # Mount Action Cable outside main process or domain.
210
-
211
- # config.action_cable.mount_path = nil
212
-
213
- # config.action_cable.url = 'wss://example.com/cable'
214
-
215
- # config.action_cable.allowed_request_origins = [ 'http://example.com', /http://example.*/ ]
216
-
217
-
218
-
219
- # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
220
-
221
- # config.force_ssl = true
222
-
223
-
224
-
225
- # Use the lowest log level to ensure availability of diagnostic information
226
-
227
- # when problems arise.
228
-
229
- config.log_level = :debug
230
-
231
-
232
-
233
- # Prepend all log lines with the following tags.
234
-
235
- config.log_tags = [ :request_id ]
236
-
237
-
238
-
239
- # Use a different cache store in production.
240
-
241
- # config.cache_store = :mem_cache_store
242
-
243
-
244
-
245
- # Use a real queuing backend for Active Job (and separate queues per environment).
246
-
247
- # config.active_job.queue_adapter = :resque
248
-
249
- # config.active_job.queue_name_prefix = "stock_info_production"
250
-
251
-
252
-
253
- config.action_mailer.perform_caching = false
254
-
255
-
256
-
257
- # Ignore bad email addresses and do not raise email delivery errors.
258
-
259
- # Set this to true and configure the email server for immediate delivery to raise delivery errors.
260
-
261
- # config.action_mailer.raise_delivery_errors = false
262
-
263
-
264
-
265
- # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
266
-
267
- # the I18n.default_locale when a translation cannot be found).
268
-
269
- config.i18n.fallbacks = true
270
-
271
-
272
-
273
- # Send deprecation notices to registered listeners.
274
-
275
- config.active_support.deprecation = :notify
276
-
277
-
278
-
279
- # Use default logging formatter so that PID and timestamp are not suppressed.
280
-
281
- config.log_formatter = ::Logger::Formatter.new
282
-
283
-
284
-
285
- # Use a different logger for distributed setups.
286
-
287
- # require 'syslog/logger'
288
-
289
- # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
290
-
291
-
292
-
293
- if ENV["RAILS_LOG_TO_STDOUT"].present?
294
-
295
- logger = ActiveSupport::Logger.new(STDOUT)
296
-
297
- logger.formatter = config.log_formatter
298
-
299
- config.logger = ActiveSupport::TaggedLogging.new(logger)
300
-
301
- end
302
-
303
-
304
-
305
- # Do not dump schema after migrations.
306
-
307
- config.active_record.dump_schema_after_migration = false
308
-
309
-
310
-
311
- # Inserts middleware to perform automatic connection switching.
312
-
313
- # The `database_selector` hash is used to pass options to the DatabaseSelector
314
-
315
- # middleware. The `delay` is used to determine how long to wait after a write
316
-
317
- # to send a subsequent read to the primary.
318
-
319
- #
320
-
321
- # The `database_resolver` class is used by the middleware to determine which
322
-
323
- # database is appropriate to use based on the time delay.
324
-
325
- #
326
-
327
- # The `database_resolver_context` class is used by the middleware to set
328
-
329
- # timestamps for the last write to the primary. The resolver uses the context
330
-
331
- # class timestamps to determine how long to wait before reading from the
332
-
333
- # replica.
334
-
335
- #
336
-
337
- # By default Rails will store a last write timestamp in the session. The
338
-
339
- # DatabaseSelector middleware is designed as such you can define your own
340
-
341
- # strategy for connection switching and pass that into the middleware through
342
-
343
- # these configuration options.
344
-
345
- # config.active_record.database_selector = { delay: 2.seconds }
346
-
347
- # config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver
348
-
349
- # config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session
350
-
351
- end
352
-
353
- ```
354
-
355
287
  ### 試したこと1
356
288
 
357
289
  参考記事で,config/environment/production.rbファイルにconfig.assets.js_compressor = :uglifierという記述をconfig.assets.js_compressor = Uglifier.new(harmony: true)に編集する,と書いてありましたが、自分のファイルにはその元々その記述がなかったため、config.assets.js_compressor = Uglifier.new(harmony: true)を新たに追記してみましたが、上手くいきませんでした。
@@ -469,3 +401,59 @@
469
401
  というエラーが出ました。
470
402
 
471
403
  ここに原因がありそうと思っているのですが...話をややこしくしてしまったのか...
404
+
405
+
406
+
407
+ ###追記
408
+
409
+ #####app/assets/stylesheets/application.scss を css に書き換えてRAILS_ENV=production bundle exec rails assets:precompile実行
410
+
411
+ ![イメージ説明](de1df0d2f10619d7056c806737996160.png)
412
+
413
+ #####app/assets/config/manifest.js
414
+
415
+ ```
416
+
417
+ //= link_tree ../images
418
+
419
+ //= link_directory ../stylesheets .css
420
+
421
+ ```
422
+
423
+ #####config/initializers/assets.rb
424
+
425
+ ```
426
+
427
+ # Be sure to restart your server when you modify this file.
428
+
429
+
430
+
431
+ # Version of your assets, change this if you want to expire all your assets.
432
+
433
+ Rails.application.config.assets.version = '1.0'
434
+
435
+
436
+
437
+ # Add additional assets to the asset load path.
438
+
439
+ # Rails.application.config.assets.paths << Emoji.images_path
440
+
441
+ # Add Yarn node_modules folder to the asset load path.
442
+
443
+ Rails.application.config.assets.paths << Rails.root.join('node_modules')
444
+
445
+
446
+
447
+ # Precompile additional assets.
448
+
449
+ # application.js, application.css, and all non-JS/CSS in the app/assets
450
+
451
+ # folder are already added.
452
+
453
+ # Rails.application.config.assets.precompile += %w( admin.js admin.css )
454
+
455
+ ```
456
+
457
+ #####pp Rails.application.config.assets; の結果
458
+
459
+ ![イメージ説明](a5d2249c3c6a17c18fe97fd730423b31.png)

1

試したこと6を追記

2021/02/17 13:23

投稿

taba.3011
taba.3011

スコア12

test CHANGED
File without changes
test CHANGED
@@ -16,21 +16,7 @@
16
16
 
17
17
  ```
18
18
 
19
- [d86058c4-3e19-4839-8911-fe7410f859ec] 7:
20
-
21
- [d86058c4-3e19-4839-8911-fe7410f859ec] 8: <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">
22
-
23
- [d86058c4-3e19-4839-8911-fe7410f859ec] 9: <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/js/bootstrap.bundle.min.js" integrity="sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW" crossorigin="anonymous"></script>
24
-
25
- [d86058c4-3e19-4839-8911-fe7410f859ec] 10: <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
26
-
27
- [d86058c4-3e19-4839-8911-fe7410f859ec] 11: <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
28
-
29
- [d86058c4-3e19-4839-8911-fe7410f859ec] 12: <script src='https://cdnjs.cloudflare.com/ajax/libs/vue/1.0.10/vue.js'></script>
30
-
31
- [d86058c4-3e19-4839-8911-fe7410f859ec] 13: <script src='https://cdnjs.cloudflare.com/ajax/libs/marked/0.3.5/marked.js'></script>
32
-
33
- [d86058c4-3e19-4839-8911-fe7410f859ec]
19
+
34
20
 
35
21
  [d86058c4-3e19-4839-8911-fe7410f859ec] app/views/layouts/application.html.erb:10
36
22
 
@@ -449,3 +435,37 @@
449
435
  2日ほどこのエラーと戦っているのですが、設定ファイルをいじったりunicornやnginxを再起動しまくっているうちに、何が何だかわからなくなってしまいました。
450
436
 
451
437
  解決方法をご存知の方がいらっしゃれば、ぜひご教授していただけると幸いです
438
+
439
+
440
+
441
+ ####追記 試したこと6
442
+
443
+ シークレットキーあたりが怪しいと思い、
444
+
445
+ ローカル環境で一度credentials.yml.encファイルを削除し、作り直しました。
446
+
447
+ ```
448
+
449
+ rm credentials.yml.enc
450
+
451
+ ```
452
+
453
+ ```
454
+
455
+ rails credentials:edit
456
+
457
+ ```
458
+
459
+ その後、ec2内の方のアプリのcredentials.yml.encファイルに、ローカル環境で作り直したcredentials.yml.encをコピーしました。
460
+
461
+ それからbundle exec rails assets:precompile RAILS_ENV=productionを実行すると、
462
+
463
+ ```
464
+
465
+ ActiveSupport::MessageEncryptor::InvalidMessage: ActiveSupport::MessageEncryptor::InvalidMessage
466
+
467
+ ```
468
+
469
+ というエラーが出ました。
470
+
471
+ ここに原因がありそうと思っているのですが...話をややこしくしてしまったのか...