Michael Buffington

Small Tweak for Typo

Tuesday, January 24 2006

I haven’t created a patch or even submitted a ticket for this yet because I’m not sure if all of the unit tests still pass, but if you’re having trouble with Typo’s requirement that all images in a theme reside in the “images” folder, and not in any subdirectories of “images”, these two simple changes will fix it:

config/routes.rb
From:

map.connect ‘images/theme/:filename’,
:controller => ‘theme’, :action => ‘images’

To:
map.connect ‘images/theme/*filename’,
:controller => ‘theme’, :action => ‘images’

Changing the symbol :filename so that the route accepts an array of the name filename allows anything after images/theme to come in without Typo getting confused about how to route it.

app/controller/theme_controller.rb
From:

def images
render_theme_item(:images, params[:filename])
end

To:
def images
render_theme_item(:images, params[:filename].join(“/”))
end

Now that params[:filename] is an array, all we need to do is format the elements in the array as a string with slashes to traverse down into the requested directory. Pretty simple.