Help us understand the problem. What is going on with this article?

asset_path について

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

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は何をやってくれてるのか

aokiyasuhiro8376
シュッとしたエンジニアになるため日々精進してます。 自分の勉強と備忘録のためぼちぼち更新していきます。 Haml・SCSS・Ruby・Ruby on Rails・JavaScript・jQuery・ GitHub・AWS 等々 を かじりかじりかじり。
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした