Luiz Vitor Martinez Cardoso
2008-Oct-07 04:03 UTC
attachment_fu: saving content in multiple models ?!
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"
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---