前提・実現したいこと
プログラミング初心者です。
rails6でアプリを開発しており、bootstrapでcardを実装しようとしています。
cardの中に任意の画像を表示させたいです。
bootstrapを使用しているため、image_tagではなくimgタグで記述しています。
発生している問題・エラーメッセージ
画像が表示されず、山のアイコンのような画像が表示されます。
ターミナルとコンソール上には以下のエラーが表示されます。
ターミナル ActionController::RoutingError (No route matches [GET] "/assets/images/depositphotos_1982682-stock-photo-reading-in-front-of-cheminey.jpg"): コンソール Failed to load resource: the server responded with a status of 404 (Not Found)
該当のソースコード
Ruby
1<div class="card" style="width: 18rem;"> 2 <img class="card-img-top" src="../../assets/images/depositphotos_1982682-stock-photo-reading-in-front-of-cheminey.jpg" alt="Card image cap"> 3 <div class="card-body"> 4 <h5 class="card-title">Card title</h5> 5 <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p> 6 <a href="#" class="btn btn-primary">Go somewhere</a> 7 </div> 8</div>
試したこと
恐らく指定した画像パスが正しくないことが原因であると思います。
絶対パスと相対パス両方での指定を試みましたが、非表示のままでした。
現状は相対パスで画像のパスを指定しており、正しく記述していると思います。
../の使い方が間違っているのでしょうか。
非常に初歩的な質問で申し訳ありませんが、ご相談に乗って頂けると嬉しいです。
補足情報(FW/ツールのバージョンなど)
ディレクトリ構造は以下の通りです。
./app/
├── assets
│ ├── config
│ │ └── manifest.js
│ ├── images
│ │ └── depositphotos_1982682-stock-photo-reading-in-front-of-cheminey.jpg
│ └── stylesheets
│ ├── application.scss
│ └── books.scss
省略
└── views
├── books
│ └── index.html.erb ←ここで画像を表示させたいです。
省略
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/03/30 06:53