what's the best approach for making reference for assets, for nested urls.
e.g. if in my html I r开发者_开发百科efer to image this way: , it does not work when the url is myapp/admin/edit/1 or any custom url.
Use the asset tag helpers, image_tag
and so on:
http://api.rubyonrails.org/classes/ActionView/Helpers/AssetTagHelper.html
Wherever your current path is should make no difference, as accessing assets should be done from root, e.g. /images/whatever.jpg
, /stylesheets/whatever.css
The asset tag helpers will make this transparent, and additionally, they will transform paths for you if you ever use an asset host other than your web server. For example.
# if you define a different asset_host, Rails will handle it.
ActionController::Base.asset_host = "assets.example.com"
image_tag("rails.png")
# => <img alt="Rails" src="http://assets.example.com/images/rails.png?1230601161" />
精彩评论