I''m having trouble wrapping my head around how to do this. If I have photo and photoset models with an :image file_column in photo, how do I process a directory of photos, rather than one at at time through a form, what''s the syntax? ps = Photoset.new Dir.glob(''*.jpg'').each do |f| p = Photo.new p.image = f <--------- This is the linkage I don''t believe is this easy? ps.images << p end Anyone else done something like this? Google and list archive search haven''t done it for me. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Fluffy Hippo wrote:> p.image = f <--------- This is the linkage I don''t believe is this > easy?It might be that easy. I would test. There is a part of file_column called file_compat.rb that has a comment which says this: # This bit of code allows you to pass regular old files to # file_column. file_column depends on a few extra methods that the # CGI uploaded file class adds. We will add the equivalent methods # to file objects if necessary by extending them with this module. This # avoids opening up the standard File class which might result in # naming conflicts. So give it a try. It might just work. The comments in the plugin indicate it should be supported. Eric --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Almost that easy ... you have to pass a File object instead of a string and then it works fine. Using your variables ... fh = File.open(f) p.image = fh p.save On 12/1/06, Fluffy Hippo <fluffyhippo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I''m having trouble wrapping my head around how to do this. > > If I have photo and photoset models with an :image file_column in photo, > how do I process a directory of photos, rather than one at at time through > a form, what''s the syntax? > > ps = Photoset.new > Dir.glob(''*.jpg'').each do |f| > p = Photo.new > p.image = f <--------- This is the linkage I don''t believe is this > easy? > ps.images << p > end > > > Anyone else done something like this? Google and list archive search > haven''t done it for me. > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---