Forum: Ruby on Rails attachment_fu: saving content in multiple models ?!

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.
Luiz Vitor Martinez C. (Guest)
on 2008-10-07 08:04
(Received via mailing list)

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/'


I tried to do something like:

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

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!


Luiz Vitor Martinez C.
cel.: (11) 8187-8662
engineer student at

"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
eu puder ser"
This topic is locked and can not be replied to.