Problem in Attachement_fu... help

Hello, i’m using the very popular attachment_fu plugin, almost
everything is awesome.
But I spend all day to make attachment_fu update a existing file with
no success.

I’m doing simple upload where my model product has_one
product_image(another model), in this product_image i call
has_attachment and everything works fine for new products. But when i
try update a product record and his image i get the error: undefined
method `uploaded_data=’ for #Product:0x679c664 , i thinking
update_attributes doesn’t work in attachment_fu when use associations.

Someone can help?

My code here:

class Product < ActiveRecord::Base
has_one :product_image, :dependent => :destroy
validates_presence_of :name, :category

def uploaded_picture=(picture) # used for create new product_image
associated with product
self.product_image = ProductImage.new
self.product_image.uploaded_data = picture
end
end

class ProductImage < ActiveRecord::Base
has_attachment :content_type => :image,
:storage => :file_system,
:max_size => 500.kilobytes,
:resize_to => ‘640x480>’,
:processor => ‘MiniMagick’,
:thumbnails => { :thumb => ‘50x50>’ },
:path_prefix => “public/images/upload/products”

validates_as_attachment

belongs_to :product

end

My controller is default generated by scaffold.
My views are multipart and in new.html.erb i had:
<%= file_field :uploaded_picture %>

, and in edit.html.erb i had:
<%= file_field :uploaded_data %>

Some can help??? Thanks.

I read some posts about problems with attachment_fu and i think this
can be a bug.
Someone i have maded this operation using has_one association betewen
models?

Change uploaded_photo to uploaded_data and see if that makes a
difference.

I can’t do this, because my new.html.erb is a view for product model
and not for product_image, this is the reason for uploaded_picture=
method.
And the problem not is when call new but update and uploaded_picture
is used only in new.

I think the reason is because updated_data is a method for
product_image class, but even i use <%= f.file_field :uploaded_picture
%>(field for my virtual atribute uploaded_picture) in my edit view i
got errors, but this error:

undefined method `content_type’ for “Fotos-132.jpg”:String

Why can’t find content_type inside attachement_fu?

Some one can help? How can i update existing attachment when this file
is stored in diferent table and associated with other table?
I bought Advanced Rails recipes but the chapter about upload had the
same problem.

undefined method `content_type’ for “Fotos-132.jpg”:String

Your form isn’t a multipart form.


Ryan B.
http://www.frozenplague.net
Feel free to add me to MSN and/or GTalk as this email.

Putz… o my god… shame. thanks for help Ryan.

do you find it working with rails 2 ?

Yes, working with rails 2.0.2

I’ve just installed this plugin and I have problem with using with
amazon s3.
Urls are created in that way
http(s)://:server/:bucket_name/:table_name/:id/:file
instead of :
http(s)://:bucket_name.:server/:table_name/:id/:file

I can fix it manually in this place but I’m not sure if it will work
properly at all.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs