初心者です。備忘録のため。残します。
超基本的な内容です。
エラー内容
Sprockets::DoubleLinkError
Rails にて erb ファイルを作成して、表示しようとしたら上記発生。ターミナル確認すると以下記述あり。
ActionView::Template::Error (Multiple files with the same output path cannot be linked ("style.css")
In "/Users/○○/git/photo_submission/app/assets/config/manifest.js" these files were linked:
- /Users/○○/git/photo_submission/app/assets/stylesheets/style.css
- /Users/○○/git/photo_submission/app/assets/stylesheets/style.scss
):
原因
調べてみたら、Rails は rails new したときに自動で作成される views/layauts/application.html.erb を参照して HTML ファイルを作るようです。
assets ファイル以下のデータ群を一つに圧縮する(アセットパイプライン)。
views/layauts/application.html.erb
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
あとで erb ファイルに変更しようと思って、先に普通の HTML ファイルで作成しており、深く考えずに style.scss を作成していた。VSCode の拡張機能の Live Sass Compiler でstyle.css も自動で作成されており、これがエラーの原因。
assets/stylesheets/application.css に style.scss の記述を写し、stylesheets 直下には application.css だけ残すようにファイルの構造を調整して、再度出力すると問題なく表示できた。