# Attachment\_fu: setting the default image

**URL:** <https://www.ruby-forum.com/t/attachment-fu-setting-the-default-image/120187>\
**Category:** Rails\
**Created:** [November 14, 2007, 5:36pm UTC](https://www.ruby-forum.com/t/attachment-fu-setting-the-default-image/120187 "2007-11-14T17:36:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 14, 2007, 5:36pm UTC](https://www.ruby-forum.com/t/attachment-fu-setting-the-default-image/120187/1 "2007-11-14T17:36:39Z")

</div>

Hey everyone, quick question ,

how can I set the default image using attachment\_fu? (this is not a  
quesiton on how to use it, cause I got it working and the first image  
is being set as default)

Thing is, I want the user to have the option to change the default  
image to whichever he likes, currently I have this in the user\_image  
controller:

```
def default_image
  @image = UserImage.find(params[:id])
  @userimg = UserImage.find(:all, :conditions => ['parent_id is

```

null AND user\_id=?’,@image.user\_id])  
@userimg.each do |daimg|  
daimg.update\_attributes(:default =\> false)  
end  
@image.set\_as\_default  
redirect\_to user\_url(current\_user)  
end

in the model:

def set\_as\_default  
self.default = true  
self.save  
end

BUT this takes way too long because it re-creates every single image  
and thumbnail again…

what other way can I do this ? (where the already uploaded image dont  
get re-created again)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 16, 2007, 3:50pm UTC](https://www.ruby-forum.com/t/attachment-fu-setting-the-default-image/120187/2 "2007-11-16T15:50:33Z")

</div>

anyone ?

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [January 14, 2008, 10:49am UTC](https://www.ruby-forum.com/t/attachment-fu-setting-the-default-image/120187/3 "2008-01-14T10:49:51Z")

</div>

_Bump_

I have same scenario…want to let the user change an image associated  
with a product as being the default.  
Using a radio button.

[http://pastie.org/138562](http://pastie.org/138562) – currently, it always sets the first image  
as the default.

They should be able to pick one, or change the existing default with  
radio button selection.

On Nov 16 2007, 6:50 am, “removed\_email\_address@domain.invalid” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
