# Attachment\_fu not saving other attributes (like width, height)

**URL:** <https://www.ruby-forum.com/t/attachment-fu-not-saving-other-attributes-like-width-height/123979>\
**Category:** Rails\
**Created:** [December 23, 2007, 12:43am UTC](https://www.ruby-forum.com/t/attachment-fu-not-saving-other-attributes-like-width-height/123979 "2007-12-23T00:43:45Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![chovy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ecd19e/32.png) [@chovy](https://www.ruby-forum.com/u/chovy)\
**Post date:** [December 23, 2007, 12:43am UTC](https://www.ruby-forum.com/t/attachment-fu-not-saving-other-attributes-like-width-height/123979/1 "2007-12-23T00:43:45Z")

</div>

[http://pastie.caboo.se/131759](http://pastie.caboo.se/131759)

I’m only getting the basic filename, product\_id for the image, and size  
(kb).

I am _not_ getting the thumbnail generated (in db or filesystem), nor  
is it resizing the image as depicted in the Picture model

## | id | parent\_id | content\_type | filename | thumbnail | size | width | height | product\_id |

| 3 | NULL | image/png | ico\_lh\_creds\_untrained.png | NULL  
| 3064 | NULL | NULL | 21 |  
| 4 | NULL | image/png | ico\_msg\_ok.png | NULL  
| 6662 | NULL | NULL | 21 |

I am unclear what I’m doing wrong here.

Please see the source example at [Parked at Loopia](http://pastie.caboo.se/131759)

–  
Anthony E.  
408-656-2473  
[http://anthony.ettinger.name](http://anthony.ettinger.name)

@pets = Pets.find\_all\_by\_species(‘dog’)  
@pets.each do |dog| {  
if dog.name == ‘Farley’  
dog.nick = ‘Sir Barks-A-lot’  
elsif dog.name == ‘Bonita’  
dog.nick = ‘Princess Boo’  
else  
dog.nick = ‘Doggie?’  
end  
}

---

<div class="post-metadata">

**Author:** ![chovy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ecd19e/32.png) [@chovy](https://www.ruby-forum.com/u/chovy)\
**Post date:** [December 23, 2007, 1:06am UTC](https://www.ruby-forum.com/t/attachment-fu-not-saving-other-attributes-like-width-height/123979/2 "2007-12-23T01:06:32Z")

</div>

On Dec 22, 2007 6:43 PM, Anthony E. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> * * *
> 
> | 3 | NULL | image/png | ico\_lh\_creds\_untrained.png | NULL  
> | 3064 | NULL | NULL | 21 |  
> | 4 | NULL | image/png | ico\_msg\_ok.png | NULL  
> | 6662 | NULL | NULL | 21 |
> 
> I am unclear what I’m doing wrong here.
> 
> Please see the source example at [http://pastie.caboo.se/131759](http://pastie.caboo.se/131759)

You probably don’t have an image processor installed correctly then.

–  
Rick O.  
[http://lighthouseapp.com](http://lighthouseapp.com)  
[http://weblog.techno-weenie.net](http://weblog.techno-weenie.net)  
[http://mephistoblog.com](http://mephistoblog.com)

---

<div class="post-metadata">

**Author:** ![chovy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ecd19e/32.png) [@chovy](https://www.ruby-forum.com/u/chovy)\
**Post date:** [December 23, 2007, 1:16pm UTC](https://www.ruby-forum.com/t/attachment-fu-not-saving-other-attributes-like-width-height/123979/3 "2007-12-23T13:16:10Z")

</div>

On Dec 22, 4:05 pm, “Rick O.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > I am _not_ getting the thumbnail generated (in db or filesystem), nor  
> > I am unclear what I’m doing wrong here.
> 
> > Please see the source example athttp://pastie.caboo.se/131759
> 
> You probably don’t have an image processor installed correctly then.

Could it possibly be the way I’m adding the uploaded image?

@product = Product.find(params[:id])  
@product.pictures.build(params[:picture])  
if @product.update\_attributes(params[:product])  
flash[:notice] = ‘Product was successfully updated.’  
redirect\_to :action =\> ‘show’, :id =\> @product  
else  
render :action =\> ‘edit’  
end

I saw some other posts about a bug with attachment\_fu and  
update\_attributes. How do I ensure I"ve got the image processor  
installed properly?

---

<div class="post-metadata">

**Author:** ![chovy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ecd19e/32.png) [@chovy](https://www.ruby-forum.com/u/chovy)\
**Post date:** [December 23, 2007, 4:11pm UTC](https://www.ruby-forum.com/t/attachment-fu-not-saving-other-attributes-like-width-height/123979/4 "2007-12-23T16:11:22Z")

</div>

I am unable however to make the case where an image is optional.

I want to require an image on :create, but make it option  
on :edit/:update

---

<div class="post-metadata">

**Author:** ![chovy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ecd19e/32.png) [@chovy](https://www.ruby-forum.com/u/chovy)\
**Post date:** [December 23, 2007, 3:06pm UTC](https://www.ruby-forum.com/t/attachment-fu-not-saving-other-attributes-like-width-height/123979/5 "2007-12-23T15:06:55Z")

</div>

On Dec 23, 4:15 am, chovy [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > I am _not_ getting the thumbnail generated (in db or filesystem), nor  
> > > I am unclear what I’m doing wrong here.  
> > > flash[:notice] = ‘Product was successfully updated.’  
> > > redirect\_to :action =\> ‘show’, :id =\> @product  
> > > else  
> > > render :action =\> ‘edit’  
> > > end
> 
> I saw some other posts about a bug with attachment\_fu and  
> update\_attributes. How do I ensure I"ve got the image processor  
> installed properly?

I apologize for jumping the gun. Re-emerging imagemagick and re-  
installing “gem install rmagick” fixed the problem.

---

<div class="post-metadata">

**Author:** ![chovy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ecd19e/32.png) [@chovy](https://www.ruby-forum.com/u/chovy)\
**Post date:** [December 24, 2007, 4:39am UTC](https://www.ruby-forum.com/t/attachment-fu-not-saving-other-attributes-like-width-height/123979/6 "2007-12-24T04:39:12Z")

</div>

I was able to get the effect with this line inside the “update” method  
for ProductController:

@product.pictures.build(params[:picture]) unless params[:picture]  
[:uploaded\_data].blank?

if @product.update\_attributes(params[:product])  
…  
end

---

<div class="post-metadata">

**Author:** ![chovy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ecd19e/32.png) [@chovy](https://www.ruby-forum.com/u/chovy)\
**Post date:** [December 24, 2007, 3:48am UTC](https://www.ruby-forum.com/t/attachment-fu-not-saving-other-attributes-like-width-height/123979/7 "2007-12-24T03:48:21Z")

</div>

Enclose the image upload in its own form

Sent from my iPhone

---

<div class="post-metadata">

**Author:** ![chovy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ecd19e/32.png) [@chovy](https://www.ruby-forum.com/u/chovy)\
**Post date:** [December 24, 2007, 12:27pm UTC](https://www.ruby-forum.com/t/attachment-fu-not-saving-other-attributes-like-width-height/123979/8 "2007-12-24T12:27:36Z")

</div>

When I try to validate height and width in my image model (which is  
using attachement\_fu) it fails validation. Yet when I examine the  
database, those fields are properly filled in. I’ve removed the  
validation for now, yet this bothers me. I guess attachment\_fu must  
have overridden the model save! method but I don’t see where this  
happens. Any clues would be appreciated.

Is there a way to validate that the image processor is installed  
correctly? I find that generating thumbnails simply hangs, so I’ve  
turned that off while I work on other parts of the project.

I’m developing on windows xp and rails 2.0.2. Are there any mods or  
updates needed for rails 2.0.2?

fredistic

---

<div class="post-metadata">

**Author:** ![chovy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ecd19e/32.png) [@chovy](https://www.ruby-forum.com/u/chovy)\
**Post date:** [December 24, 2007, 7:55pm UTC](https://www.ruby-forum.com/t/attachment-fu-not-saving-other-attributes-like-width-height/123979/9 "2007-12-24T19:55:17Z")

</div>

On Dec 24, 3:26 am, fredistic [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m developing on windows xp and rails 2.0.2. Are there any mods or  
> updates needed for rails 2.0.2?
> 
> fredistic

There is a bug I saw people talk about where you need to add a sleep  
1, before you load the picture to your model. Try searching this list  
for “attachment\_fu windows bug”
