質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
unicorn

Unicornは、汎用のRackアプリケーションサーバ。RackとWebサーバーの機能を併せ持ちます。レスポンス処理や、Nginx単体がRackの機能をサポートしていない事から、一般的にはNginx+Unicorn+Railsの構成を取って用います。

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails 6

Ruby on Rails 6は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

nginx

nginixは軽量で高性能なwebサーバーの1つです。BSD-likeライセンスのもとリリースされており、あわせてHTTPサーバ、リバースプロキシ、メールプロキシの機能も備えています。MacOSX、Windows、Linux、上で動作します。

AWS(Amazon Web Services)

Amazon Web Services (AWS)は、仮想空間を機軸とした、クラスター状のコンピュータ・ネットワーク・データベース・ストーレッジ・サポートツールをAWSというインフラから提供する商用サービスです。

Q&A

0回答

1053閲覧

アセットコンパイルが上手くいかない

taba.3011

総合スコア12

unicorn

Unicornは、汎用のRackアプリケーションサーバ。RackとWebサーバーの機能を併せ持ちます。レスポンス処理や、Nginx単体がRackの機能をサポートしていない事から、一般的にはNginx+Unicorn+Railsの構成を取って用います。

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails 6

Ruby on Rails 6は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

nginx

nginixは軽量で高性能なwebサーバーの1つです。BSD-likeライセンスのもとリリースされており、あわせてHTTPサーバ、リバースプロキシ、メールプロキシの機能も備えています。MacOSX、Windows、Linux、上で動作します。

AWS(Amazon Web Services)

Amazon Web Services (AWS)は、仮想空間を機軸とした、クラスター状のコンピュータ・ネットワーク・データベース・ストーレッジ・サポートツールをAWSというインフラから提供する商用サービスです。

0グッド

0クリップ

投稿2021/02/15 12:26

編集2021/02/17 13:23

前提・実現したいこと

アプリをデプロイしたらブラウザでWe're sorry, but something went wrong.というエラーが出ました。
ログを確認したところ
ActionView::Template::Error (The asset "application.css" is not present in the asset pipeline.
というエラーが出ていました。

発生している問題・エラーメッセージ

[d86058c4-3e19-4839-8911-fe7410f859ec] app/views/layouts/application.html.erb:10 [983873fe-9610-4044-89f0-7fa37184c9f1] ActionView::Template::Error (The asset "application.css" is not present in the asset pipeline. ):

該当のソースコード

#####assets/stylesheets/application.scss

省略 * It is generally better to create a new file per style scope. * */ @import "articles"; @import "bootstrap-sprockets"; @import "bootstrap";

#####config/environment/production.rb

Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. # Code is not reloaded between requests. config.cache_classes = true # Eager load code on boot. This eager loads most of Rails and # your application in memory, allowing both threaded web servers # and those relying on copy on write to perform better. # Rake tasks automatically ignore this option for performance. config.eager_load = true # Full error reports are disabled and caching is turned on. config.consider_all_requests_local = false config.action_controller.perform_caching = true # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"] # or in config/master.key. This key is used to decrypt credentials (and other encrypted files). # config.require_master_key = true # Disable serving static files from the `/public` folder by default since # Apache or NGINX already handles this. config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? # Compress CSS using a preprocessor. # config.assets.css_compressor = :sass # Do not fallback to assets pipeline if a precompiled asset is missed. config.assets.compile = ture # Enable serving of images, stylesheets, and JavaScripts from an asset server. # config.action_controller.asset_host = 'http://assets.example.com' # Specifies the header that your server uses for sending files. # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX # Store uploaded files on the local file system (see config/storage.yml for options). config.active_storage.service = :local # Mount Action Cable outside main process or domain. # config.action_cable.mount_path = nil # config.action_cable.url = 'wss://example.com/cable' # config.action_cable.allowed_request_origins = [ 'http://example.com', /http://example.*/ ] # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. # config.force_ssl = true # Use the lowest log level to ensure availability of diagnostic information # when problems arise. config.log_level = :debug # Prepend all log lines with the following tags. config.log_tags = [ :request_id ] # Use a different cache store in production. # config.cache_store = :mem_cache_store # Use a real queuing backend for Active Job (and separate queues per environment). # config.active_job.queue_adapter = :resque # config.active_job.queue_name_prefix = "stock_info_production" config.action_mailer.perform_caching = false # Ignore bad email addresses and do not raise email delivery errors. # Set this to true and configure the email server for immediate delivery to raise delivery errors. # config.action_mailer.raise_delivery_errors = false # Enable locale fallbacks for I18n (makes lookups for any locale fall back to # the I18n.default_locale when a translation cannot be found). config.i18n.fallbacks = true # Send deprecation notices to registered listeners. config.active_support.deprecation = :notify # Use default logging formatter so that PID and timestamp are not suppressed. config.log_formatter = ::Logger::Formatter.new # Use a different logger for distributed setups. # require 'syslog/logger' # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') if ENV["RAILS_LOG_TO_STDOUT"].present? logger = ActiveSupport::Logger.new(STDOUT) logger.formatter = config.log_formatter config.logger = ActiveSupport::TaggedLogging.new(logger) end # Do not dump schema after migrations. config.active_record.dump_schema_after_migration = false # Inserts middleware to perform automatic connection switching. # The `database_selector` hash is used to pass options to the DatabaseSelector # middleware. The `delay` is used to determine how long to wait after a write # to send a subsequent read to the primary. # # The `database_resolver` class is used by the middleware to determine which # database is appropriate to use based on the time delay. # # The `database_resolver_context` class is used by the middleware to set # timestamps for the last write to the primary. The resolver uses the context # class timestamps to determine how long to wait before reading from the # replica. # # By default Rails will store a last write timestamp in the session. The # DatabaseSelector middleware is designed as such you can define your own # strategy for connection switching and pass that into the middleware through # these configuration options. # config.active_record.database_selector = { delay: 2.seconds } # config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver # config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session end

試したこと1

参考記事で,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)を新たに追記してみましたが、上手くいきませんでした。

試したこと2

config/environment/production.rbファイルのconfig.assets.compile = falseをtrueにしました。
###試したこと3
config/environment/production.rbファイルの
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?を
config.public_file_server.enabled = trueに編集しました。

試したこと4

参考記事ではbundle exec rails assets:precompile RAILS_ENV=productionで手動デプロイをしたあと

terminal

1[username@ip-10-0-11-63 app]$ cd public/assets/ 2[username@ip-10-0-11-63 assets]$ ls 3application-111ac35321e379f53529ace176fe931c952be73f7ffd688b815ec21878126685.js 4application-111ac35321e379f53529ace176fe931c952be73f7ffd688b815ec21878126685.js.gz 5application-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.css 6application-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.css.gz

となっていました。
しかし自分の方ではbundle exec rails assets:precompile RAILS_ENV=productionを実行した後、assetsディレクトリが存在しませんでした。

terminal

1[username@ip-10-0-11-63 app]$ cd public 2[username@ip-10-0-11-63 public]$ ls 3404.html 422.html 500.html apple-touch-icon.png apple-touch-icon-precomposed.png favicon.ico robots.txt

試したこと5

unicornとnginxを切断した上でコンパイルしました。
unicornやnginxの再起動は何回もしています。

補足情報(FW/ツールのバージョンなど)

rails 6.0.3.5
ruby 2.6.5
mysqld 5.7.33

アプリの方で見た目を整える際に、scssファイルとbootstrap両方使ってます。
どちらかに統一しなければいけないというエラーなのでしょうか...

2日ほどこのエラーと戦っているのですが、設定ファイルをいじったりunicornやnginxを再起動しまくっているうちに、何が何だかわからなくなってしまいました。
解決方法をご存知の方がいらっしゃれば、ぜひご教授していただけると幸いです

####追記 試したこと6
シークレットキーあたりが怪しいと思い、
ローカル環境で一度credentials.yml.encファイルを削除し、作り直しました。

rm credentials.yml.enc
rails credentials:edit

その後、ec2内の方のアプリのcredentials.yml.encファイルに、ローカル環境で作り直したcredentials.yml.encをコピーしました。
それからbundle exec rails assets:precompile RAILS_ENV=productionを実行すると、

ActiveSupport::MessageEncryptor::InvalidMessage: ActiveSupport::MessageEncryptor::InvalidMessage

というエラーが出ました。
ここに原因がありそうと思っているのですが...話をややこしくしてしまったのか...

###追記
#####app/assets/stylesheets/application.scss を css に書き換えてRAILS_ENV=production bundle exec rails assets:precompile実行
イメージ説明
#####app/assets/config/manifest.js

//= link_tree ../images //= link_directory ../stylesheets .css

#####config/initializers/assets.rb

# Be sure to restart your server when you modify this file. # Version of your assets, change this if you want to expire all your assets. Rails.application.config.assets.version = '1.0' # Add additional assets to the asset load path. # Rails.application.config.assets.paths << Emoji.images_path # Add Yarn node_modules folder to the asset load path. Rails.application.config.assets.paths << Rails.root.join('node_modules') # Precompile additional assets. # application.js, application.css, and all non-JS/CSS in the app/assets # folder are already added. # Rails.application.config.assets.precompile += %w( admin.js admin.css )

#####pp Rails.application.config.assets; の結果
イメージ説明

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

neko_daisuki

2021/02/15 22:55

bundle exec rails assets:precompile RAILS_ENV=production するとどのように表示されますか? また、development環境で bundle exec rails assets:precompile すると public/assetsにファイルは出力されますか?
taba.3011

2021/02/16 07:03

bundle exec rails assets:precompile RAILS_ENV=production すると何も起こらず次のプロンプトが表示されます。development環境で bundle exec rails assets:precompile すると public/assetsにファイルは出力されました
neko_daisuki

2021/02/16 15:56

試してみて欲しいこと assets以下のファイルを消した後に RAILS_ENV=production を先にもってきて RAILS_ENV=production bundle exec rails assets:precompile app/assets/stylesheets/application.scss を app/assets/stylesheets/application.css.scss にして 上記の手順を実行 app/assets/stylesheets/application.scss を css に書き換えて(ファイル名も中身も)上記の手順を実行 追記して欲しいこと app/assets/config/manifest.js config/initializers/assets.rb bin/rails c -e production して pp Rails.application.config.assets; の結果
taba.3011

2021/02/17 13:30

assets以下のファイルを消した後にRAILS_ENV=production bundle exec rails assets:precompile実行。 app/assets/stylesheets/application.scss を app/assets/stylesheets/application.css.scss にして上記実行。 ここまでは上手く実行されました。 app/assets/stylesheets/application.scss を css に書き換えて(ファイル名も中身も)上記の手順を実行の部分でエラーが出ました。 追記に関して、文字数の関係で一部画像であることご容赦ください。
neko_daisuki

2021/02/17 18:58

RAILS_ENV=production bundle exec rails assets:precompile --trace でエラーの箇所を特定できるかもしれません。 拡張子がscssだとエラーが出ないのはscssを認識していないのかも。 rails new したプロジェクトと張り付けていただいた Rails.application.config.assets を比べると precompile と compile、resolve_with の値が異なってますが、よく分かりません・・・
taba.3011

2021/02/18 05:41

neko_daisuki様親身に対応してくださりありがとうございます。 AWSへのデプロイが初めてなので、知らないうちにどこかいじってしまったのだと思います。。。 RAILS_ENV=production bundle exec rails assets:precompile --traceコマンドを参考にさせていただき、原因の究明に努めてみます。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問