Reputation: 93
I am facing the weird error of sprockets with tilt gem.
Basically I am loading images on ERB template (generated with Tilt) with the image tag but when the template is rendered it shows Sprockets::Rails::Helper:: AssetNotFound
.
The asset "button.jpg" is not present in the asset pipeline.
.
I have configured my assets path properly below I will be attaching the file.
And another thing is when I hit the back button and refresh the page the image gets loaded with the proper assets.
I have tried with changing assets paths as well as tried rake assets:precompile
but still it remains the same.
All the assets are located at:
app/assets/images
merge.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
template.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]
development.rb
config.assets.compile = true
config.assets.debug = true
config.assets.quiet = true
Please write down the comments if anything is unclear.
Thanks in advance!
Upvotes: 0
Views: 3198
Reputation: 93
By adding this my problem is solved.
<center><%= link_to image_tag(ActionController::Base.helpers.asset_path("button.jpg") , style: "max-width: 100%;height: auto;") , "#{@email.url}" %></center>
Thanks if anyone can detail why this works!
Upvotes: 1