Bonjour,
J’utilise attachment_fu désormais en lieu et place de file_column.
Tout fonctionne très bien excepté lors de l’update de mon objet image
(upload d’un nouveau fichier image).
Voici mon model Image :
class Image < ActiveRecord::Base
belongs_to :produit
has_attachment :content_type => :image,
:storage => :file_system,
:max_size => 1.megabyte,
:resize_to => ‘320x200>’,
:path_prefix => “public/upload/images_produits”,
:thumbnails => { :thumb => ‘100x100>’ },
:processor => :Rmagick
validates_as_attachment
end
Voici mon action pour l’update de l’objet image :
def maj
@produit = Produit.find_by_id(params[:id])
@image = Image.find_by_produit_id(@produit.id) || Image.new
Produit.transaction do
@image.produit = @produit
@produit.update_attributes(params[:produit])
@image.update_attributes(params[:image])
flash[:notice] = “Le produit #{@produit.titre} a été modifié avec
succès !”
redirect_to :action => ‘afficher’
end
rescue ActiveRecord::RecordInvalid => e
@image.valid?
render :action => ‘modifier’
end
Mon fichier de migration (au cas où) :
class AddProduitsImages < ActiveRecord::Migration
def self.up
create_table :images do |t|
t.column :titre, :string
t.column :produit_id, :integer
t.column :parent_id, :integer
t.column :content_type, :string
t.column :filename, :string
t.column :thumbnail, :string
t.column :size, :integer
t.column :width, :integer
t.column :height, :integer
end
say_with_time 'Ajout de la cle etrangere fk_images_produits' do
execute 'ALTER TABLE images ADD CONSTRAINT fk_images_produits
FOREIGN KEY (produit_id) REFERENCES produits(id) ON DELETE CASCADE’
end
end
def self.down
drop_table :images
end
end
J’obtiens le message d’erreur suivant :
undefined method `content_type’ for “101_0178.jpg”:String
alors, attachment_fu buggé où j’ai zappé quelques chose ?
Merci pour vos réponses.
Jérémy.