views:

241

answers:

1

I am working on maintaing an old code base and I'm migrating attachment_fu to paperclip. I migrated one thing but now I'm having a small issue.

There's a partial that renders images given the type of image and a thumbnail style. I fixed the part to render the image and that's fine, but the "else" assumes that there actually is no photo or image. I basically just want a completely detached list of the style=> geometry pairs that aren't dependent on a particular object, but I can't seem to do this without doing things like creating a new object and pulling the string from there, and even that didn't work correctly. Is there a way I could pull it straight out of paperclip or straight out of the model? The old method was using something refelect_on_association which I don't even understand... Help please. thanks :)

A: 

Paperclip has a notion of "default_url", if you specify this in your model it will attempt to pull the default url if an image isn't assigned to that object yet (your "else" case).

The default_url accepts the :style interpolations, so you can setup your style/geometry pairs in a separate folder.

Step 1

Put your default images in a directory like "/images/users/avatar/missing/".

Example file names:

missing_thumb.png
missing_small.png

Step 2

Add this line to your has_attached_file declaration in your model:

:default_url => "/images/:class/:attachment/missing/missing_:style.png"
Mike Buckbee
I don't know if I can do this if I'm using s3? It also seems kind of excessive since the code is there - all I need to do is pull a geometry with a style from a given type of image's model.
Stacia
You can definitely do this using S3. I'm also not sure how this is excessive: a folder with some images in it and one line of code.
Mike Buckbee