Hiall,
I want to make an image_tag from within a controller in order to be
able to present a link (with a status image) in a view. Here is my
controller method (in file webca_controller.rb, hence WebcaController)
def untouched_status_image_tag
image_tag(“open”, { :alt => “Offen”, :title => “Offen”, :size =>
“12x12”, :class => “b_icon” } )
end
I have a myapp/public/images/open.png in place, however this seems not
enough When executing the call to the above method, rails complains
with the following:
You have a nil object when you didn’t expect it!
The error occured while evaluating nil.request
…/actionpack-1.12.0/lib/action_view/helpers/asset_tag_helper.rb:150:in
compute_public_path' .../actionpack-1.12.0/lib/action_view/helpers/asset_tag_helper.rb:120:in
image_path’
…/actionpack-1.12.0/lib/action_view/helpers/asset_tag_helper.rb:135:in
image_tag' #{RAILS_ROOT}/app/controllers/webca_controller.rb:90:in
untouched_status_image_tag’
compute_public_path looks like so:
def compute_public_path(source, dir, ext)
source = “/#{dir}/#{source}” unless source.first == “/” ||
source.include?(":")
source = “#{source}.#{ext}” unless
source.split("/").last.include?(".")
source = “#{@controller.request.relative_url_root}#{source}” unless
%r{^[-a-z]+://} =~ source
source = ActionController::Base.asset_host + source unless
source.include?(":")
source
end
Why does @controller evaluate to nil in there? What is it that I’m
doing wrong again
Thx for your patience with me
cheers
Martin