Blank image for non-existant image URLs


#1

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

#2

How about adding the missing photo as the user’s
photo upon user creation?


– Tom M.


#3

On 4/1/06, Michael B. removed_email_address@domain.invalid 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 L.
http://AllTom.com/
http://GadgetLife.org/