I don''t know if this is a Ruby or a Rails question, but it has to do
with
the availability of an object in the controller to a helper. Here is the
scenario:
I have an ImagesController class, and of course a image/list view. To help
me display the images uniformly, I wanted to create a helper, much as in
4-Days:
require ''RMagick''
module ImagesHelper
def self.append_features(controller)
controller.ancestors.include?(ActionController::Base) ?
controller.add_template_helper(self) : super
end
def show_image(alttext, src, ext=''.gif'')
if src.length > 0 then
file_name = src.include?(''/'') ? src :
"/#{@request.env}/#{src}"
img_options = { "src" => file_name }
img_options["src"] += src.include?(''.'') ?
'''' : ext
img_options["border"] = "0"
img_options["alt"] = alttext
#size_of_image(src, ext)
#img_options["width"], img_options["height"]
@options[src]["width"], @options[src]["height"]
tag(''img'', img_options)
end
end
# .
end
Now, in my controller, I use what I believe to be correct...
class ImagesController < ApplicationController
helper :Images
# ...
The problem in the show_image function occurs when @request.env raises a
name_error exception. Running this with breakpointer I can stop at the top
of show_image and @request sure exists, but not in running code. Any help on
this is appreciated.
Thanks