Problema con attachment_fu

Hola

Estoy usando attachment_fu y RMagick para subir fotos, cambiar el tamaño
y crear un thumbnail.

El caso que cuando añado una imagen, la primera vez la hace bien y el
resto da error al hacer el save en el controlador. Así que tengo parar
el servidor y volver a arranzarlo y entonces la sube…

Mi código es este:

new.rhtml

New mugshot

<%= error_messages_for :whatever %>

<% form_for(:mugshot, :url => { :action => “create” },
:html => { :multipart => true }) do |f| -%>

Upload A Mugshot: <%= f.file_field :uploaded_data %>

<%= submit_tag 'Create' %>

<% end -%>

Controller

class MugshotsController < ApplicationController
def show
@mugshot = Mugshot.find(:all)
end

def create
@mugshot = Mugshot.new(params[:mugshot])
if @mugshot.save
flash[:notice] = ‘Photo saved successfully!’
render :action => “show”
else
flash[:notice] = ‘There was a problem!’
render :action => “new”
end
end
end

Model

class Mugshot < ActiveRecord::Base

has_attachment :content_type => :image,
:storage => :file_system,
:max_size => 2.megabyte,
:resize_to => ‘640x480>’,
:path_prefix => “./public/images”,
:thumbnails => { :thumb => ‘100x100>’ },
:processor => :Rmagick

    validates_as_attachment

end

¿Alguien sabe porqué puede ser?

Muchas gracias

Hola de nuevo.
Sigo sin poder resolver el problema :frowning:

¿Hay que limpiar alguna caché u otra historia?

Muchas gracias

Solucionado el problema.

He tenido que cambiar el modelo.
Tenía
:max_size => 2.megabyte

Y se ha solucionado con
:size => 0.kilobytes…3.megabytes,

Muchas gracias

Estoy comparando el log y veo varias cosas…

Log que ha funcionado

Processing MugshotsController#create (for 127.0.0.1 at 2007-10-06
12:03:35) [POST]
Session ID: a4a498d39b73b6c85343af2121023339
Parameters: {“commit”=>“Create”, “action”=>“create”,
“controller”=>“mugshots”,
“mugshot”=>{“uploaded_data”=>#<File:C:/DOCUME~1/ADMINI~1/CONFIG~1/Temp/CGI5456-1>,
“establishment_id”=>“1”}}
e[4;36;1mSQL (0.000000)e[0m e[0;1mSET SQL_AUTO_IS_NULL=0e[0m
e[4;35;1mMugshot Columns (0.000000)e[0m e[0mSHOW FIELDS FROM
mugshotse[0m
e[4;36;1mSQL (0.000000)e[0m e[0;1mBEGINe[0m
e[4;35;1mSQL (0.000000)e[0m e[0mINSERT INTO mugshots
(content_type, size, thumbnail, establishment_id, filename,
height, parent_id, width) VALUES(‘image/pjpeg’, 1321783, NULL, 1,
‘PC030030.JPG’, 480, NULL, 640)e[0m
e[4;36;1mMugshot Load (0.015000)e[0m e[0;1mSELECT * FROM mugshots
WHERE (mugshots.thumbnail = ‘thumb’ AND mugshots.parent_id = 31)
LIMIT 1e[0m
e[4;35;1mSQL (0.000000)e[0m e[0mINSERT INTO mugshots
(content_type, size, thumbnail, establishment_id, filename,
height, parent_id, width) VALUES(‘image/pjpeg’, 117200, ‘thumb’,
NULL, ‘PC030030_thumb.JPG’, 75, 31, 100)e[0m
e[4;36;1mSQL (0.079000)e[0m e[0;1mCOMMITe[0m
Rendering layoutfalseactionshow within layouts/mugshots
Rendering mugshots/show
Completed in 1.89000 (0 reqs/sec) | Rendering: 0.01500 (0%) | DB:
0.09400 (4%) | 200 OK [http://localhost/mugshots/create]

Log que da ERROR

Processing MugshotsController#create (for 127.0.0.1 at 2007-10-06
12:04:14) [POST]
Session ID: a4a498d39b73b6c85343af2121023339
Parameters: {“commit”=>“Create”, “action”=>“create”,
“controller”=>“mugshots”,
“mugshot”=>{“uploaded_data”=>#<File:C:/DOCUME~1/ADMINI~1/CONFIG~1/Temp/CGI5456-1>,
“establishment_id”=>“1”}}
e[4;35;1mMugshot Columns (0.016000)e[0m e[0mSHOW FIELDS FROM
mugshotse[0m
e[4;36;1mSQL (0.000000)e[0m e[0;1mBEGINe[0m
e[4;35;1mSQL (0.000000)e[0m e[0mCOMMITe[0m
Rendering layoutfalseactionnew within layouts/mugshots
Rendering mugshots/new
Completed in 0.48400 (2 reqs/sec) | Rendering: 0.01500 (3%) | DB:
0.01600 (3%) | 200 OK [http://localhost/mugshots/create]

Veo varias cosas que no se si son correctas:

  1. El archivo temporal de la foto se llama igual en los casos.
    OK–> <File:C:/DOCUME~1/ADMINI~1/CONFIG~1/Temp/CGI5456-1>
    KO–> <File:C:/DOCUME~1/ADMINI~1/CONFIG~1/Temp/CGI5456-1>

  2. En el que ha ido bien antes del insert hace “SET SQL_AUTO_IS_NULL=0”.
    ¿Podría ser un problema de la bbdd?

Muchas gracias.