Forum: Ruby on Rails attachment_fu, polymorphic model

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Walksalong (Guest)
on 2007-05-10 23:43
(Received via mailing list)
I'm borrowing this question from a user named Spencer on the Rails
Forums. He clearly explains the issue we're having:

"First of all, apologies, as I am probably missing something utterly

I am trying to set up a polymorphic assets model, with attachment_fu.
Essentially attachment_fu is working as I can upload directly to the
attachment model. However when I try and upload a file from another
controller (linked polymorphically) I get errors about the
content_type etc. not being in the list.

I assume this means that the params array isn't capturing the data?
How can I correct this?
in my asset model i have:

   1. belongs_to :attachable, :polymorphic => true

(and has_attachment + validates_as_attachment)

in my product model I have:

   1.   has_many :assets, :as => :attachable

in the create method in my products controller is am using:

   1. @asset =[:uploaded_data])

In my new product form I have:

   1. <%= file_field 'asset', 'uploaded_data'  %>

A yaml dump of the form content

   1. --- !map:HashWithIndifferentAccess html: multiparttrue commit:
Create product: !map:HashWithIndifferentAccess name: test body: test
title: test green: test category_ids: - "3" sidebar: "" description:
test action: create controller: admin/products asset: !
map:HashWithIndifferentAccess uploaded_data: cm_logo.jpg

The errors I get:
Assets is invalid
Content type is not included in the list
Content type can't be blank
Size is not included in the list
Size can't be blank
Filename can't be blank

Any help greatly appreciated."

Rick O. (Guest)
on 2007-05-11 00:14
(Received via mailing list)
>    1. @asset =[:uploaded_data])
> In my new product form I have:
>    1. <%= file_field 'asset', 'uploaded_data'  %>

uploaded_data is a single virtual attribute in attachment_fu.  Try: => params[:uploaded_data])

Rick O.
Walksalong (Guest)
on 2007-05-14 18:21
(Received via mailing list)
Thanks for the answer Rick. I tried your solution, but
validates_as_attachment keeps kicking it back saying the attachment is
invalid. I've tried gifs and jpegs at small sizes. When I remove the
validates_as_attachment everything is null.
This topic is locked and can not be replied to.