16
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Failed to load resource: the server responded with a status of 404 (Not Found)の原因と解決策

Posted at

問題:画像が表示できない

image.png

エラー

Failed to load resource: the server responded with a status of 404 (Not Found)

404 (Not Found)は、ファイルが見つからないという意味。
推定原因は、2つあるらしい。

①ファイルがデータベースに保存されていない
②画像がDBに保存されているけど、パスがずれてる

ファイルは保存できていた。なので、原因は、②。
参照記事:https://teratail.com/questions/3951

パスの確認

views/user/show.html.erb
<img src="<%= "/img/#{@user.id}"%>">

解決策

/img/#{@user.id}に、jpgを付け加えてみたら、パスが特定されて、無事画像が表示された。

views/user/show.html.erb
<img src="<%= "/img/#{@user.id}.jpg"%>">
16
16
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?