gberz3
2007-May-06 00:51 UTC
Attachment_fu. . .HTML involved in immediately associating an upload with a model?
All, I''m having trouble wrapping my head around how to associate my IMAGE model with my PRODUCT model. Basically I have the obligatory fields for the attachment_fu association: class CreateImages < ActiveRecord::Migration def self.up create_table :images do |t| t.column :parent_id, :integer t.column :content_type, :string t.column :filename, :string t.column :thumbnail, :string t.column :size, :integer t.column :width, :integer t.column :height, :integer end end def self.down drop_table :images end end . . .then I have the models associated through "has_many" and "belongs_to". What I can''t quite figure out is how to immediately associate an uploaded image with a product on the same "new" page. Would I set the "form_for" a PRODUCT and IMAGE independently, or would I have one nested inside the other? I''m sorry, I''ve been coding for several hours on end now, and I''m admittedly a bit rusty on my HTML form handling. Thanks, Michael --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
gberz3
2007-May-06 10:46 UTC
Re: Attachment_fu. . .HTML involved in immediately associating an upload with a model?
. . .anyone? --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
gberz3
2007-May-06 17:54 UTC
Re: Attachment_fu. . .HTML involved in immediately associating an upload with a model?
Basically I need to include two models in a single form. I guess what I''m looking for is very similar to this thread: http://www.railsforum.com/viewtopic.php?id=717 . . .but I''m not sure how to include the specific information for the attachment_fu based IMAGE model (e.g. url, html {multipart. . . . .}) Thanks, Michael --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
hal_robertson-/E1597aS9LQAvxtiuMwx3w@public.gmane.org
2007-May-07 06:47 UTC
Re: Attachment_fu. . .HTML involved in immediately associating an upload with a model?
Interesting I am working with this same problem all day today... These posts were most helpful to me, though w/ my barely functioning app I still have lots of questions myself! http://significantbits.wordpress.com/2007/04/06/using-attachment_fu-by-techno-weenie-to-add-image-attachment-support-to-your-rails-application/ http://railsgrunt.com/2007/3/14/ruby-rails-upload-multiple-files-using-acts-as-attachment My end goal is to hopefully get to having an object with multiple images attachable and editable through a single, dynamic form. If you find any more articles or code examples on how to do this, please post! Hope these help. Good luck! Hal On May 6, 10:54 am, gberz3 <gbe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Basically I need to include two models in a single form. I guess what > I''m looking for is very similar to this thread: > > http://www.railsforum.com/viewtopic.php?id=717 > > . . .but I''m not sure how to include the specific information for theattachment_fubased IMAGE model (e.g. url, html {multipart. . . . .}) > > Thanks, > Michael--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Bojan Mihelac
2007-May-08 10:34 UTC
Re: Attachment_fu. . .HTML involved in immediately associating an upload with a model?
> . . .then I have the models associated through "has_many" and > "belongs_to". What I can''t quite figure out is how to immediately > associate an uploaded image with a product on the same "new" page. > Would I set the "form_for" a PRODUCT and IMAGE independently, or would > I have one nested inside the other? I''m sorry, I''ve been coding for > several hours on end now, and I''m admittedly a bit rusty on my HTML > form handling. > > Thanks, > Michael >Michael, approach that I am using is to nest ''documents'' (or images) in product form so field for attachment_fu upload looks something like these: <input id="product[edit_documents]_1136_uploaded_data" type="file" size="30" name="product[edit_documents][1136][uploaded_data]"/> then, in model specify attributes which are set from controller attr_writer :edit_documents, :new_documents after_save :update_documents and code for handling actual uploads looks like: def update_documents opts = @edit_documents || {} documents.each { |opt| opt.destroy if !opts.has_key?(opt.id.to_s) } opts.each {|key, params| Document.find(key).update_attributes(params) } (@new_documents || []).each { |p| next if (p[:uploaded_data].size == 0 && p[:position].empty? && p[:name].empty?) self.documents.create(p) } end hope that helps a little, Bojan -- Bojan Mihelac -> Ruby on Rails and Web Developer Blog : http://source.mihelac.org --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
gberz3
2007-May-09 02:20 UTC
Re: Attachment_fu. . .HTML involved in immediately associating an upload with a model?
Bojan, Thanks for the post. I''m still slightly confused. The code you posted for the form looks like straight HTML not RHTML. Could you clarify a bit as to what is goin on there and perhaps ''rubify'' it? Thanks, Michael On May 8, 6:34 am, Bojan Mihelac <l...-3SxN1WY3PMJAfugRpC6u6w@public.gmane.org> wrote:> > . . .then I have the models associated through "has_many" and > > "belongs_to". What I can''t quite figure out is how to immediately > > associate an uploaded image with a product on the same "new" page. > > Would I set the "form_for" a PRODUCT and IMAGE independently, or would > > I have one nested inside the other? I''m sorry, I''ve been coding for > > several hours on end now, and I''m admittedly a bit rusty on my HTML > > form handling. > > > Thanks, > > Michael > > Michael, > approach that I am using is to nest ''documents'' (or images) in product > form so field forattachment_fuupload looks something like these: > > <input id="product[edit_documents]_1136_uploaded_data" type="file" > size="30" name="product[edit_documents][1136][uploaded_data]"/> > > then, in model specify attributes which are set from controller > > attr_writer :edit_documents, :new_documents > after_save :update_documents > > and code for handling actual uploads looks like: > > def update_documents > opts = @edit_documents || {} > documents.each { |opt| opt.destroy if !opts.has_key?(opt.id.to_s) } > opts.each {|key, params| > Document.find(key).update_attributes(params) > } > (@new_documents || []).each { |p| > next if (p[:uploaded_data].size == 0 && p[:position].empty? && > p[:name].empty?) > self.documents.create(p) > } > end > > hope that helps a little, > Bojan > > -- > Bojan Mihelac > -> Ruby on Rails and Web Developer Blog :http://source.mihelac.org--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
gberz3
2007-May-10 19:53 UTC
Re: Attachment_fu. . .HTML involved in immediately associating an upload with a model?
Perhaps I should handle it in the save of the Product? If the :uploaded_data var is not nil, then use it. Any thoughts? On May 8, 6:34 am, Bojan Mihelac <l...-3SxN1WY3PMJAfugRpC6u6w@public.gmane.org> wrote:> > . . .then I have the models associated through "has_many" and > > "belongs_to". What I can''t quite figure out is how to immediately > > associate an uploaded image with a product on the same "new" page. > > Would I set the "form_for" a PRODUCT and IMAGE independently, or would > > I have one nested inside the other? I''m sorry, I''ve been coding for > > several hours on end now, and I''m admittedly a bit rusty on my HTML > > form handling. > > > Thanks, > > Michael > > Michael, > approach that I am using is to nest ''documents'' (or images) in product > form so field forattachment_fuupload looks something like these: > > <input id="product[edit_documents]_1136_uploaded_data" type="file" > size="30" name="product[edit_documents][1136][uploaded_data]"/> > > then, in model specify attributes which are set from controller > > attr_writer :edit_documents, :new_documents > after_save :update_documents > > and code for handling actual uploads looks like: > > def update_documents > opts = @edit_documents || {} > documents.each { |opt| opt.destroy if !opts.has_key?(opt.id.to_s) } > opts.each {|key, params| > Document.find(key).update_attributes(params) > } > (@new_documents || []).each { |p| > next if (p[:uploaded_data].size == 0 && p[:position].empty? && > p[:name].empty?) > self.documents.create(p) > } > end > > hope that helps a little, > Bojan > > -- > Bojan Mihelac > -> Ruby on Rails and Web Developer Blog :http://source.mihelac.org--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Bojan Mihelac
2007-May-11 00:41 UTC
Re: Attachment_fu. . .HTML involved in immediately associating an upload with a model?
Michael, I take the code from HTML page as it is created with ROAR and it would be too much to post all the code here. I recommend you to download Roar and see how it is done there / it has many examples and maybe u''d like interface too. best, Bojan gberz3 wrote:> Bojan, > > Thanks for the post. I''m still slightly confused. The code you > posted for the form looks like straight HTML not RHTML. Could you > clarify a bit as to what is goin on there and perhaps ''rubify'' it? > > Thanks, > Michael > > On May 8, 6:34 am, Bojan Mihelac <l...-3SxN1WY3PMJAfugRpC6u6w@public.gmane.org> wrote: >>> . . .then I have the models associated through "has_many" and >>> "belongs_to". What I can''t quite figure out is how to immediately >>> associate an uploaded image with a product on the same "new" page. >>> Would I set the "form_for" a PRODUCT and IMAGE independently, or would >>> I have one nested inside the other? I''m sorry, I''ve been coding for >>> several hours on end now, and I''m admittedly a bit rusty on my HTML >>> form handling. >>> Thanks, >>> Michael >> Michael, >> approach that I am using is to nest ''documents'' (or images) in product >> form so field forattachment_fuupload looks something like these: >> >> <input id="product[edit_documents]_1136_uploaded_data" type="file" >> size="30" name="product[edit_documents][1136][uploaded_data]"/> >> >> then, in model specify attributes which are set from controller >> >> attr_writer :edit_documents, :new_documents >> after_save :update_documents >> >> and code for handling actual uploads looks like: >> >> def update_documents >> opts = @edit_documents || {} >> documents.each { |opt| opt.destroy if !opts.has_key?(opt.id.to_s) } >> opts.each {|key, params| >> Document.find(key).update_attributes(params) >> } >> (@new_documents || []).each { |p| >> next if (p[:uploaded_data].size == 0 && p[:position].empty? && >> p[:name].empty?) >> self.documents.create(p) >> } >> end >> >> hope that helps a little, >> Bojan >> >> -- >> Bojan Mihelac >> -> Ruby on Rails and Web Developer Blog :http://source.mihelac.org > > > > >-- Bojan Mihelac -> Ruby on Rails and Web Developer Blog : http://source.mihelac.org --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Bojan Mihelac
2007-May-11 00:41 UTC
Re: Attachment_fu. . .HTML involved in immediately associating an upload with a model?
yes, you can handle it in Product. gberz3 wrote:> Perhaps I should handle it in the save of the Product? If > the :uploaded_data var is not nil, then use it. Any thoughts? > > On May 8, 6:34 am, Bojan Mihelac <l...-3SxN1WY3PMJAfugRpC6u6w@public.gmane.org> wrote: >>> . . .then I have the models associated through "has_many" and >>> "belongs_to". What I can''t quite figure out is how to immediately >>> associate an uploaded image with a product on the same "new" page. >>> Would I set the "form_for" a PRODUCT and IMAGE independently, or would >>> I have one nested inside the other? I''m sorry, I''ve been coding for >>> several hours on end now, and I''m admittedly a bit rusty on my HTML >>> form handling. >>> Thanks, >>> Michael >> Michael, >> approach that I am using is to nest ''documents'' (or images) in product >> form so field forattachment_fuupload looks something like these: >> >> <input id="product[edit_documents]_1136_uploaded_data" type="file" >> size="30" name="product[edit_documents][1136][uploaded_data]"/> >> >> then, in model specify attributes which are set from controller >> >> attr_writer :edit_documents, :new_documents >> after_save :update_documents >> >> and code for handling actual uploads looks like: >> >> def update_documents >> opts = @edit_documents || {} >> documents.each { |opt| opt.destroy if !opts.has_key?(opt.id.to_s) } >> opts.each {|key, params| >> Document.find(key).update_attributes(params) >> } >> (@new_documents || []).each { |p| >> next if (p[:uploaded_data].size == 0 && p[:position].empty? && >> p[:name].empty?) >> self.documents.create(p) >> } >> end >> >> hope that helps a little, >> Bojan >> >> -- >> Bojan Mihelac >> -> Ruby on Rails and Web Developer Blog :http://source.mihelac.org > > > > >-- Bojan Mihelac -> Ruby on Rails and Web Developer Blog : http://source.mihelac.org --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---