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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
045393257ca8795742d87e6b2945f151?d=identicon&s=25 Luiz Vitor Martinez Cardoso (Guest)
on 2008-10-07 06:04
(Received via mailing list)
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 Cardoso
cel.: (11) 8187-8662
blog: 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"
This topic is locked and can not be replied to.