# Attachment\_fu: saving content in multiple models ?!

**URL:** <https://www.ruby-forum.com/t/attachment-fu-saving-content-in-multiple-models/150307>\
**Category:** Rails\
**Created:** [October 7, 2008, 6:04am UTC](https://www.ruby-forum.com/t/attachment-fu-saving-content-in-multiple-models/150307 "2008-10-07T06:04:19Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![lz-coelho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/8c91f0/32.png) [@lz-coelho](https://www.ruby-forum.com/u/lz-coelho)\
**Post date:** [October 7, 2008, 6:04am UTC](https://www.ruby-forum.com/t/attachment-fu-saving-content-in-multiple-models/150307/1 "2008-10-07T06:04:19Z")

</div>

Yeah,

I’m trying to solve it:

Models: User and Picture

User has\_many Pictures  
Pictures belongs\_to User

\<% form\_for(@user, :html =\> { :multipart =\> true }) do |f| %\>  
\<%= f.text\_field :anything %\>  
\<%= f.file\_field :uploaded\_data %\>  
\<% end %\>

At Picture.rb:

has\_attachment :content\_type =\> :image,  
:storage =\> :file\_system,  
:max\_size =\> 2.megabytes,  
:resize\_to =\> “640x480”,  
:path\_prefix =\> ‘public/images/’

validates\_as\_attachment

I tried to do something like:

```
@user = User.new
params[:user].each do |p|
  unless p == ':uploaded_data' # it's really an idea!
    @user = User.update_attributtes(:name, p)
  else
    @user = User.picture_id.update_attributte(:name, p)
  end
end

```

This sounds me very bad because it isn’t DRY.

How can i save the ‘:anything’ object in User model and ‘:uploaded\_data’  
object to User.picture\_id or Picture passing the user\_id ?

Thanks for your attention!

–  
Regards,

Luiz Vitor Martinez C.  
cel.: (11) 8187-8662  
blog: [rubz.org](http://rubz.org)  
engineer student at maua.br

“Posso nunca chegar a ser o melhor engenheiro do mundo, mas tenha  
certeza de  
que eu vou lutar com todas as minhas forÃ§as para ser o melhor engenheiro  
que  
eu puder ser”
