Announcement (2017-05-07): www.ruby-forum.com is now read-only since I
unfortunately do not have the time to support and maintain the forum any
more. Please see rubyonrails.org/community and ruby-lang.org/en/community
for other Rails- und Ruby-related community platforms.

Morning/Afternoon/Evening All,
Just wondering if anyone has any suggestions on forwarding requests
to invalid images (ie images that result in a 404 error) via routes.rb
or a similar method?
If possible I would like it to be based on the url so I can have
different blank pictures for different directories (ie
/images/people/user_id.jpg => /images/people/blank.jpg and
/images/hardware/hardware_id.jpg => /images/hardware/blank.jpg)
For example: an image of a persons silhouette will appear if a User
hasnt uploaded a picture for their profile
Any ideas?
- Michael

On 4/1/06, Michael Bryne <rails@mbryne.com> wrote:
> Just wondering if anyone has any suggestions on forwarding requests> to invalid images (ie images that result in a 404 error) via routes.rb> or a similar method?
I just did this recently for a similar reason--I wanted thumbnails of
images to be auto-generated if one didn't already exist. It was simple
enough: I added a route that matched 'images/somedir/:filename'. If
that route matches, you know that that file doesn't exist (because the
file would have been served instead), so you can just send the blank
file with a send_file or similar. In my case, I also saved the
thumbnail so that the next request would use it instead.
> - Michael
Sincerely,
Tom Lieber
http://AllTom.com/http://GadgetLife.org/