Hi, I''m still quite new to RoR and I am having trouble uploading files to a file system. I have been following this tutorial: http://manuals.rubyonrails.com/read/chapter/77 : 1.2.1. The simplest thing that could possibly work But when I try to save a file I get "You have a nil object when you didn''t expect it! The error occurred while evaluating nil.read" In this very simple example its the controller that does all the work: def save File.open("#{RAILS_ROOT}/public/images/testWorked.jpg", "wb") do | f| f.write(@params[''picture_file''].read) end Why is my @params[''picture_file''] object empty? Any assistance would be much appreciated. Tim --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi, If these images are coming from a browser, they need to have multi- part encoding. Then, you''ll need Ruby code to decode this. Why don''t you use some complete plugin such as acts_as_attachment or attachment_fu? http://weblog.techno-weenie.net/articles/acts_as_attachment Amir --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Amir, Thanks for the reply, I want to save the files to the file system and not to a database. fto set the enctype I used multipart => true and the html output is set to enctype="multipart/form-data" so that should be fine. Is the ruby code: File.open("#{RAILS_ROOT}/public/images/testWorked.jpg", "wb") do | f| f.write(@params[''picture_file''].read) incorrect for dealing with file uploads? I''ll see if i can find a plugin that allows saves to the file system. Tim On Jul 8, 1:50 pm, helzer <amir.hel...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > If these images are coming from a browser, they need to have multi- > part encoding. Then, you''ll need Ruby code to decode this. > > Why don''t you use some complete plugin such as acts_as_attachment or > attachment_fu?http://weblog.techno-weenie.net/articles/acts_as_attachment > > Amir--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Give attachment_fu by Rick Olson a try - it''s very good and allows you to save to the file system, database, or Amazon S3. There is also ''uploadcolumn''. On Jul 8, 9:16 am, fernando <tim.fernandezh...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Amir, > > Thanks for the reply, > > I want to save the files to the file system and not to a database. fto > set the enctype I used multipart => true and the html output is set to > enctype="multipart/form-data" so that should be fine. > Is the ruby code: > > File.open("#{RAILS_ROOT}/public/images/testWorked.jpg", "wb") do | > f| > f.write(@params[''picture_file''].read) > > incorrect for dealing with file uploads? > > I''ll see if i can find a plugin that allows saves to the file system. > > Tim > > On Jul 8, 1:50 pm, helzer <amir.hel...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hi, > > > If these images are coming from a browser, they need to have multi- > > part encoding. Then, you''ll need Ruby code to decode this. > > > Why don''t you use some complete plugin such as acts_as_attachment or > > attachment_fu?http://weblog.techno-weenie.net/articles/acts_as_attachment > > > Amir--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---