Problem in Attachement_fu... help

34 views
Skip to first unread message

Daniel Lopes

unread,
Jan 22, 2008, 7:48:50 PM1/22/08
to Ruby on Rails: Talk
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.

Daniel Lopes

unread,
Jan 22, 2008, 8:21:52 PM1/22/08
to Ruby on Rails: Talk
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?

Ryan Bigg

unread,
Jan 22, 2008, 8:47:13 PM1/22/08
to rubyonra...@googlegroups.com
Change uploaded_photo to uploaded_data and see if that makes a difference.

Daniel Lopes

unread,
Jan 22, 2008, 10:09:09 PM1/22/08
to Ruby on Rails: Talk
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.

Daniel Lopes

unread,
Jan 22, 2008, 10:30:37 PM1/22/08
to Ruby on Rails: Talk
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.

Ryan Bigg

unread,
Jan 22, 2008, 10:47:06 PM1/22/08
to rubyonra...@googlegroups.com

undefined method `content_type' for "Fotos-132.jpg":String


Your form isn't a multipart form.

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

Daniel Lopes

unread,
Jan 22, 2008, 10:56:58 PM1/22/08
to Ruby on Rails: Talk
Putz... o my god... shame. thanks for help Ryan.

On 23 jan, 01:47, "Ryan Bigg" <radarliste...@gmail.com> wrote:
> > undefined method `content_type' for "Fotos-132.jpg":String
>
> Your form isn't a multipart form.
>
> --
> Ryan Bigghttp://www.frozenplague.net

mariek

unread,
Jan 24, 2008, 4:36:56 AM1/24/08
to Ruby on Rails: Talk
do you find it working with rails 2 ?

Daniel Lopes

unread,
Jan 26, 2008, 1:29:38 PM1/26/08
to Ruby on Rails: Talk
Yes, working with rails 2.0.2

mariek

unread,
Jan 28, 2008, 7:30:45 AM1/28/08
to Ruby on Rails: Talk
I've just installed this plugin and I have problem with using with
amazon s3.
Urls are created in that way
<tt>http(s)://:server/:bucket_name/:table_name/:id/:file</tt>
instead of :
<tt>http(s)://:bucket_name.:server/:table_name/:id/:file</tt>

I can fix it manually in this place but I'm not sure if it will work
properly at all.
Reply all
Reply to author
Forward
0 new messages