我在资产管道中有一个像这样的图像:“app / assets / images / wholesale_analysis.png”。在我的模板中,我有这个标签<%= image_tag("wholesale_analysis.png") %>
,但它找不到图像。它返回图像标记的文本而不是图像,即使我在图像标记中提供了'alt:'。图像标记在布局中工作,但不在模板中。发生了什么事?
@Kamil rails console的结果......
`C:/Users/CMMC/Documents/Sites/cmmc/config/environments/development.rb:50:in
block in <top (required)>': undefined method `config' for #<Rack::Sendfile:0x5321250> (NoMethodError)
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/railties-5.0.2/lib/rails/railtie.rb:209:in `instance_eval'
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/railties-5.0.2/lib/rails/railtie.rb:209:in `configure'
from C:/Users/CMMC/Documents/Sites/cmmc/config/environments/development.rb:1:in `<top (required)>'
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/activesupport-5.0.2/lib/active_support/dependencies.rb:293:in `require'
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/activesupport-5.0.2/lib/active_support/dependencies.rb:293:in `block in require'
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/activesupport-5.0.2/lib/active_support/dependencies.rb:259:in `load_dependency'
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/activesupport-5.0.2/lib/active_support/dependencies.rb:293:in `require'
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/railties-5.0.2/lib/rails/engine.rb:600:in `block (2 levels) in <class:Engine>'
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/railties-5.0.2/lib/rails/engine.rb:599:in `each'
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/railties-5.0.2/lib/rails/engine.rb:599:in `block in <class:Engine>'
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/railties-5.0.2/lib/rails/initializable.rb:30:in `instance_exec'
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/railties-5.0.2/lib/rails/initializable.rb:30:in `run'
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/railties-5.0.2/lib/rails/initializable.rb:55:in `block in run_initializers'
from C:/Ruby23/lib/ruby/2.3.0/tsort.rb:228:in `block in tsort_each'
from C:/Ruby23/lib/ruby/2.3.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
from C:/Ruby23/lib/ruby/2.3.0/tsort.rb:422:in `block (2 levels) in each_strongly_connected_component_from'
from C:/Ruby23/lib/ruby/2.3.0/tsort.rb:431:in `each_strongly_connected_component_from'
from C:/Ruby23/lib/ruby/2.3.0/tsort.rb:421:in `block in each_strongly_connected_component_from'
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/railties-5.0.2/lib/rails/initializable.rb:44:in `each'
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/railties-5.0.2/lib/rails/initializable.rb:44:in `tsort_each_child'
from C:/Ruby23/lib/ruby/2.3.0/tsort.rb:415:in `call'
from C:/Ruby23/lib/ruby/2.3.0/tsort.rb:415:in `each_strongly_connected_component_from'
from C:/Ruby23/lib/ruby/2.3.0/tsort.rb:349:in `block in each_strongly_connected_component'
from C:/Ruby23/lib/ruby/2.3.0/tsort.rb:347:in `each'
from C:/Ruby23/lib/ruby/2.3.0/tsort.rb:347:in `call'
from C:/Ruby23/lib/ruby/2.3.0/tsort.rb:347:in `each_strongly_connected_component'
from C:/Ruby23/lib/ruby/2.3.0/tsort.rb:226:in `tsort_each'
from C:/Ruby23/lib/ruby/2.3.0/tsort.rb:205:in `tsort_each'
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/railties-5.0.2/lib/rails/initializable.rb:54:in `run_initializers'
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/railties-5.0.2/lib/rails/application.rb:352:in `initialize!'
from C:/Users/CMMC/Documents/Sites/cmmc/config/environment.rb:5:in `<top (required)>'
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/railties-5.0.2/lib/rails/application.rb:328:in `require'
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/railties-5.0.2/lib/rails/application.rb:328:in `require_environment!'
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/railties-5.0.2/lib/rails/commands/commands_tasks.rb:157:in `require_application_and_environment!'
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/railties-5.0.2/lib/rails/commands/commands_tasks.rb:77:in `console'
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/railties-5.0.2/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/railties-5.0.2/lib/rails/commands.rb:18:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
答案 0 :(得分:0)
删除“wholesale”和“analysis.png”之间的文件名空间,如:wholesale_analysis.png或wholesaleanalysis.png 并改变你的图像标签:
<%= image_tag("wholesale_analysis.png") %>
答案 1 :(得分:0)
我建议将图像放在你/ public direcotry中,因为它们不应该像css和js文件一样预先编译。
如果您确实希望将它们放入资源中,则应尝试:<%= image_tag("/assets/wholesale_analysis.png") %>
答案 2 :(得分:0)
@Xenedra将图像放在assets /文件夹中,让标记为
<%= image_tag("wholesale_analysis.png") %>
答案 3 :(得分:0)
我修复了我的问题...我的文件只是命名为.html而不是.html.erb。现在一切正常!感谢您提出的所有建议。