从控制台访问 image_tag 助手 nil 错误
我正在尝试从控制台访问 image_tag 帮助程序。
(在 ruby 1.9.2,rails 3.0.1 中)
我尝试了解决方案
helper.image_tag("rails.png")
,即使
foo = ActionView::Base.new
foo.image_tag "rails.png"
我总是遇到相同的错误
TypeError: can't convert nil into String
from /home/tomi/.rvm/gems/ruby-1.9.2-p180@lovethis/gems/actionpack-3.0.1/lib/action_view/helpers/asset_tag_helper.rb:790:in `join'
from /home/tomi/.rvm/gems/ruby-1.9.2-p180@lovethis/gems/actionpack-3.0.1/lib/action_view/helpers/asset_tag_helper.rb:790:in `rails_asset_id'
from /home/tomi/.rvm/gems/ruby-1.9.2-p180@lovethis/gems/actionpack-3.0.1/lib/action_view/helpers/asset_tag_helper.rb:813:in `rewrite_asset_path'
from /home/tomi/.rvm/gems/ruby-1.9.2-p180@lovethis/gems/actionpack-3.0.1/lib/action_view/helpers/asset_tag_helper.rb:742:in `compute_public_path'
from /home/tomi/.rvm/gems/ruby-1.9.2-p180@lovethis/gems/actionpack-3.0.1/lib/action_view/helpers/asset_tag_helper.rb:561:in `image_path'
from /home/tomi/.rvm/gems/ruby-1.9.2-p180@lovethis/gems/actionpack-3.0.1/lib/action_view/helpers/asset_tag_helper.rb:631:in `image_tag'
I'm trying to access image_tag helper from console.
(in ruby 1.9.2, rails 3.0.1)
I tryed out solutions
helper.image_tag("rails.png")
even
foo = ActionView::Base.new
foo.image_tag "rails.png"
I always get the same error
TypeError: can't convert nil into String
from /home/tomi/.rvm/gems/ruby-1.9.2-p180@lovethis/gems/actionpack-3.0.1/lib/action_view/helpers/asset_tag_helper.rb:790:in `join'
from /home/tomi/.rvm/gems/ruby-1.9.2-p180@lovethis/gems/actionpack-3.0.1/lib/action_view/helpers/asset_tag_helper.rb:790:in `rails_asset_id'
from /home/tomi/.rvm/gems/ruby-1.9.2-p180@lovethis/gems/actionpack-3.0.1/lib/action_view/helpers/asset_tag_helper.rb:813:in `rewrite_asset_path'
from /home/tomi/.rvm/gems/ruby-1.9.2-p180@lovethis/gems/actionpack-3.0.1/lib/action_view/helpers/asset_tag_helper.rb:742:in `compute_public_path'
from /home/tomi/.rvm/gems/ruby-1.9.2-p180@lovethis/gems/actionpack-3.0.1/lib/action_view/helpers/asset_tag_helper.rb:561:in `image_path'
from /home/tomi/.rvm/gems/ruby-1.9.2-p180@lovethis/gems/actionpack-3.0.1/lib/action_view/helpers/asset_tag_helper.rb:631:in `image_tag'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我没有真正的答案给你,但根据我的发现,这似乎是不可能的。 nil 错误来自此行,因为
config.assets_dir
is nil:It's nil because config =
{}
。我相信它是空的,因为在 actionpack-3.0.7/action_view/base.rbcontroller
的第 220 行中,它是 nil:我知道这没有多大帮助,但如果有人能弄清楚如何覆盖它在控制台启动时也许它会起作用。
顺便说一句,你为什么要在控制台中执行此操作?似乎将其放入视图并重新加载也同样容易。
I don't have a real answer for you but based on what I've found it doesn't seem to be possible. The nil error is coming from this line because
config.assets_dir
is nil:It's nil because config =
{}
. And I believe it's empty because in line 220 in actionpack-3.0.7/action_view/base.rbcontroller
is nil:I know that doesn't help much but if someone can figure out how to override that at console start maybe it'll work.
As an aside, why do you want to do that in the console anyway? Seems it'd be just as easy to put it into a view and hit reload.