Forum: Ruby on Rails Blank image for non-existant image URLs

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.
Michael B. (Guest)
on 2006-04-02 07:11
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
Tom M. (Guest)
on 2006-04-02 09:57
(Received via mailing list)
How about adding the missing photo as the user's
photo upon user creation?

--
-- Tom M.
Tom L. (Guest)
on 2006-06-12 07:13
(Received via mailing list)
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/
This topic is locked and can not be replied to.