# Attachment\_fu

**URL:** <https://www.ruby-forum.com/t/attachment-fu/162088>\
**Category:** Rails\
**Created:** [March 5, 2009, 4:44pm UTC](https://www.ruby-forum.com/t/attachment-fu/162088 "2009-03-05T16:44:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![chimorito](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/54ee81/32.png) [@chimorito](https://www.ruby-forum.com/u/chimorito)\
**Post date:** [March 5, 2009, 4:44pm UTC](https://www.ruby-forum.com/t/attachment-fu/162088/1 "2009-03-05T16:44:54Z")

</div>

First at all sorry if my english is not the best

I have a problem with this plugin. It has been installed because we need  
to upload images in our web. We need 3 kinds of images with different  
sizes.

this is our code:

Image model:

class Image \< ActiveRecord::Base  
.  
.  
.

has\_attachment :content\_type =\> [‘image/jpeg’, ‘image/pjpeg’,  
‘image/gif’, ‘image/jpg’, ‘image/png’],  
:storage =\> :file\_system,  
:path\_prefix =\> ‘public/images’,  
:size =\> 1.kilobyte…300.kilobytes,  
:resize\_to =\> ‘700\>’,  
:thumbnails =\> { :titular1 =\> ‘220\>’,  
:titular2 =\> ‘150\>’, :foro =\> ‘440\>’ },  
:processor =\> :MiniMagick

validates\_as\_attachment

* * *

the name of the controller is titulares. The code is like that :

class TitularesController \< ApplicationController  
.  
.  
.  
def edit  
@titulo = “Editar titular”  
@titular = Contenido.find(params[:id])  
end  
.  
.  
.  
def create  
@titular=Contenido.new(params[:contenido])  
@titular.subtipo\_id=Subtipo::TITULARES

```
# Actualizo el usuario, incrementando sus puntos y su nÂº de posts de

```

## blog autor = Usuario.find(@titular.usuario\_id) estadisticas\_up(autor.id, Subtipo::TITULARES) autor.update\_attribute(“puntos”, autor.puntos + @titular.puntos\_msg) autor.update\_attribute(“puntos\_anual”, autor.puntos\_anual + @titular.puntos\_msg)

## /_this is the part of code for the images_/

```
respond_to do |format|
  if @titular.save
    #guardo las imagenes
    unless (image = params[:image]).nil?
      img = Image.new(image.merge({:usuario_id =>

```

## session[:usuario\_id], :contenido\_id =\> @titular.id, :orden =\>1})) img.save end format.html { redirect\_to(portada\_titulares\_path) } format.xml { render :xml =\> @titular, :status =\> :created, :location =\> @titular } else format.html { render :action =\> “new” } format.xml { render :xml =\> @titular.errors, :status =\> :unprocessable\_entity } end end end . . .

OK, when I edit a titular there’s no problem. I can add or edit a photo  
perfectly and in my BBDD there are the 3 images with the respective  
size. the problem exits whe i want to create a titular, I can add an  
image but my BBDD only stores the original image with the original size.  
There is not the copies with another sizes.

I donÂ´t know because the anothers sizes there arenÂ´t written in the  
BBDD…any help please???

---

<div class="post-metadata">

**Author:** ![chimorito](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/54ee81/32.png) [@chimorito](https://www.ruby-forum.com/u/chimorito)\
**Post date:** [March 5, 2009, 5:07pm UTC](https://www.ruby-forum.com/t/attachment-fu/162088/2 "2009-03-05T17:07:59Z")

</div>

I replace img.save with img.save! and the result is the same.

---

<div class="post-metadata">

**Author:** ![chimorito](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/54ee81/32.png) [@chimorito](https://www.ruby-forum.com/u/chimorito)\
**Post date:** [March 5, 2009, 5:23pm UTC](https://www.ruby-forum.com/t/attachment-fu/162088/3 "2009-03-05T17:23:17Z")

</div>

solved, it doesnÂ´t work fine in localhost but in the server there’s no  
problem
