Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
3
Help us understand the problem. What is going on with this article?
@aokiyasuhiro8376

asset_path について

More than 1 year has passed since last update.

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

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

3
Help us understand the problem. What is going on with this article?
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
aokiyasuhiro8376
シュッとしたエンジニアになるため日々精進してます。 自分の勉強と備忘録のためぼちぼち更新していきます。 Haml・SCSS・Ruby・Ruby on Rails・JavaScript・jQuery・ GitHub・AWS 等々 を かじりかじりかじり。

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
3
Help us understand the problem. What is going on with this article?