--prefix, url_for and image_tag

First time here, so I hope this isn’t a FAQ (although I did check
the faq).

I’m using mongrel_cluster with --prefix, and it is very slick. Thanks
for that. But I had one problem. At one point in my little app, I
have something like this:

image_tag(url_for(:action => 'picture', :id => 1), :size =>

“160x200”)

In this scenario, the modified prefix behavior causes the prefix to
be added twice. I get this output:

http://mysite/my-prefix/my-prefix/picture/1

I may be doing this wrong. It does work properly without --prefix in
the mix, and i can see how both these methods might add the prefix,
causing this problem. Is this a bug? Known problem? Limitation of –
prefix? Or just a confused poster?

Thanks!

Geoff


Geoff C. | 602.384.1804
9 Tips for FileMaker 9

I had to modify image_tag and add in a “nostrip” attribute. If there’s
a better way, please post it up.

def image_tag(source, options = {})
options.symbolize_keys!
source = source+".png" unless source =~ /.[gif|jpg|png]/
if options.has_key?(:nostrip)
options[:src] = image_path(source)
else
options[:src] = image_path(source).gsub(//myPrefix/,’’)
end
options[:alt] ||= File.basename(options[:src],
‘.*’).split(’.’).first.capitalize
if options[:size]
options[:width], options[:height] = options[:size].split(“x”)
options.delete :size
end
tag(“img”, options)
end

On Oct 26, 2007, at 6:22 AM, Joey G. wrote:

I had to modify image_tag and add in a “nostrip” attribute. If there’s
a better way, please post it up.

Would it be reasonable to check if source already begins with the
prefix, and not prepend it in that case? I realize this would fail in
some rare cases, but my guess is it would be the right behavior a
majority of the time, and when it isn’t you could work around it,
perhaps with a “force” attribute or something similar, or simply by
hard-coding the url.

As it is now, you need a workaround for a typical case. With this
change, I think you would need a workaround for an atypical case.

Does that make sense? I can patch it if there’s some consensus that
it would be a worthwhile patch.

Thanks!

Geoff


Geoff C. | 602.384.1804
9 Tips for FileMaker 9

actually I thought this was on a different list. My solution solves a
rails issue that I had, and isn’t really meant for mongrel
specifically, so as I said, there may be something better.

I was actually fixing the rails problem of using the incorrect path
since my rails application is tacked onto an existing server. I needed
to serve images from within the rails app and from the root of the
server using image_tag, which my solution allows.

Enable serving of images, stylesheets, and javascripts from an asset

server
config.action_controller.asset_host = “http://dev.website.com