开发者

accessing image_tag helper from console nil error

开发者 https://www.devze.com 2023-03-15 09:25 出处:网络
I\'m trying to access image_tag helper from console. (in ruby 1.9.2, rails 3.0.1) I tryed out solutions

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/开发者_Python百科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 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:

path = File.join(config.assets_dir, source)

It's nil because config = {}. And I believe it's empty because in line 220 in actionpack-3.0.7/action_view/base.rb controller is nil:

config = controller && controller.respond_to?(:config) ? controller.config : {}

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号