开发者

using paperclip to get list of style/geometry pairs, even without valid object

开发者 https://www.devze.com 2022-12-09 18:04 出处:网络
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.

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 t开发者_如何学运维hat'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 :)


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"
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号