【发布时间】:2020-09-16 19:38:17
【问题描述】:
我正面临带有倾斜宝石的链轮的奇怪错误。
基本上,我正在使用图像标签在 ERB 模板(使用 Tilt 生成)上加载图像,但是当模板被渲染时,它显示 Sprockets::Rails::Helper:: AssetNotFound.The asset "button.jpg" is not present in the asset pipeline..
我已经在下面正确配置了我的资产路径,我将附加文件。
另一件事是当我点击后退按钮并刷新页面时,图像会加载正确的资产。
我尝试过更改资产路径并尝试过rake assets:precompile,但它仍然保持不变。
所有资产位于:
app/assets/images
合并.rb
class Generator
include ApplicationHelper
include ActionView::Helpers::AssetTagHelper
include Sprockets::Rails::Helper
def initialize(template, scope = {})
scope.each do |k, v|
instance_variable_set k, v
end
f = "#{Rails.root}/app/views/#{template}.html.erb" if File.exist? "#{Rails.root}/app/views/#{template}.html.erb"
if f
@template = Tilt::ERBTemplate.new(f)
else
f = "#{Rails.root}/app/views/#{template}" if File.exist? "#{Rails.root}/app/views/#{template}"
@template = Tilt.new(f)
end
end
def request
ActionDispatch::Request.new({})
end
def render
@template.render(self) ===> Here is the render error
end
end
模板.erb
<div class="facility-button">
<center><%= link_to image_tag("button.jpg" , style: "max-width: 100%;height: auto;") , "#{@email.url}" %></center>
</div>
config/initializers/assets.rb
Rails.application.config.assets.version = '1.0'
Rails.application.config.assets.precompile += %w[vendor.js]
开发.rb
config.assets.compile = true
config.assets.debug = true
config.assets.quiet = true
如果有不清楚的地方,请写下 cmets。
提前致谢!
【问题讨论】:
标签: ruby-on-rails ruby sprockets tilt