So in my model I have different sizes for my avatar:
has_attached_file :avatar,
:styles => {
:thumb => "60x60>",
:small => "80x80>",
:medium => "140x140>",
:large => "300x300>"},
:default_url => "/images/default_avatar.png"
Now when I call model_instance.avatar.url(:small)
it will return "/images/default_avatar.png" if there is no avatar. It will also return the same result for any style I choose.
I want to make the default images change upon change of style so that when I call model_instance.avatar.url(:small)
it should return "/images/default_avatar_small.png" and if I call model_instance.avatar.url(:large)
it should return "/images/default_avatar_large.png"
How can I make paperclip assign different default avatar for each style?
The :style
can be included in the default url string which allows you to make it dynamic:
has_attached_file :avatar,
:styles => {
:thumb => "60x60>",
:small => "80x80>",
:medium => "140x140>",
:large => "300x300>"},
:default_url => "/images/default_avatar_:style.png"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With