9
6

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.

asset_path について

Posted at

便利と思ったので備忘録。

asset_path について

画面上にimageを表示する際、
'/assets/titel.png'と記述する事も多いですが、

asset_pathを使えば、

= image_tag asset_path("title.png")
↑で
app/assets/images/title.pngを参照してくれます。
(プロダクション環境でも参照可能)

他にも参考に
application.js というファイルが assets/javascripts に存在する場合
'/assets/application.js' が、=>asset_path('application.js') てな感じ。

image.png というファイルが assets/images に存在する場合
'/assets/image.png'が、=>asset_path('image.png') てな感じ。

config.assets.digest = true な環境で application.css というファイルが assets/stylesheets に存在する場合
'/assets/application817776380c2b21405e00e88cbdd215e1.css'が、=> asset_path('application.css') てな感じ。

参考記事
Railsのasset_pathは何をやってくれてるのか

9
6
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
9
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?