Ruby on rails 如何获取资产根路径?
我知道,它返回一个资源的html标记。如果未给出绝对路径,则资源将装载在Ruby on rails 如何获取资产根路径?,ruby-on-rails,ruby,ruby-on-rails-4,asset-pipeline,Ruby On Rails,Ruby,Ruby On Rails 4,Asset Pipeline,我知道,它返回一个资源的html标记。如果未给出绝对路径,则资源将装载在资产下 如何创建此资源根路径?我希望避免在我的应用程序中使用硬编码的文件。join('assets','other_resource')。我想您可以: File.join(Rails.root, 'app', 'assets','other_resource') 但我通常更喜欢: asset_path 您也可以从CSS和JS中使用:即 .class { background-image: url(<%= asset
资产下
如何创建此资源根路径?我希望避免在我的应用程序中使用硬编码的文件。join('assets','other_resource')
。我想您可以:
File.join(Rails.root, 'app', 'assets','other_resource')
但我通常更喜欢:
asset_path
您也可以从CSS和JS中使用:即
.class { background-image: url(<%= asset_path 'image.png' %>) }
.class{background image:url()}
确切地说,你在寻找什么还不清楚
但是,假设需要图像资源的相对路径,可以使用:
如果需要图像资源的绝对路径,可以使用:
您是否尝试了资产路径()
?
image_path("other_resource.png") # => /assets/other_resource.png
image_url("other_resource.png") # => http://example.com/assets/other_resource.png