8
7

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 3 years have passed since last update.

【Rails】開発者とユーザー画像の保存場所と、使い方をまとめました

Last updated at Posted at 2020-08-13

画像の保存場所

保存するファイルの用途 保存場所
開発者が用意するファイル app/assets/images配下
ユーザーがアップロードしたファイル public配下

HTMLから、画像を呼び出したい時

html.erb

# app/assets/images/logo.pngの場合
<%= image_tag 'logo.png' %>

<img src="/assets/logo.png" alt="" >
html.erb
# public/logo.pngの場合
<%= image_tag '/logo.png' %>

Sassから、画像を呼び出したい時


// app/assets/images/logo.pngの場合
h1 {
  background-image: image-url('logo.png')
}
8
7
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
8
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?