So I am following the directions on the RoR wiki for uploading images (the new 2.0.2 directions) : http://wiki.rubyonrails.org/rails/pages/HowtoUploadFiles The files upload beautifully, but I don''t know how to access the images since it''s not inserting the file name into "cover" when the file posts. It leaves it null. How can I say: def write_file if @file_data ... ... ... set cover to "#{id}.#{extension}" end end Any help would be appreciated! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
yaphi wrote:> So I am following the directions on the RoR wiki for uploading images > (the new 2.0.2 directions) : http://wiki.rubyonrails.org/rails/pages/HowtoUploadFiles > > The files upload beautifully, but I don''t know how to access the > images since it''s not inserting the file name into "cover" when the > file posts. It leaves it null. How can I say: > > def write_file > if @file_data > ... > ... > ... > set cover to "#{id}.#{extension}" > end > endYou mean this? def write_file if @file_data File.makedirs("#{ALBUM_COVER_STORAGE_PATH}/#{id}") File.open("#{ALBUM_COVER_STORAGE_PATH}/#{id}/#{id}.#{extension}", "w") { |file| file.write(@file_data.read) } # put calls to other logic here - resizing, conversion etc. end end In that example, your current object _is_ the model. You could write self, for example, and get your model''s attributes. To update, use update_attribute like this: self.update_attribute :cover, "#{id}.#{extension}" However, I don''t know if that will infinitely recurse, because you are inside an after_save event. Does update trigger another after_save event? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks for the reply! Yes update triggers an after_save because I can overwrite the image by editing it. I will try this, thank you very much. On May 25, 2:05 am, Phlip <phlip2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> yaphi wrote: > > So I am following the directions on the RoR wiki for uploading images > > (the new 2.0.2 directions) :http://wiki.rubyonrails.org/rails/pages/HowtoUploadFiles > > > The files upload beautifully, but I don''t know how to access the > > images since it''s not inserting the file name into "cover" when the > > file posts. It leaves it null. How can I say: > > > def write_file > > if @file_data > > ... > > ... > > ... > > set cover to "#{id}.#{extension}" > > end > > end > > You mean this? > > def write_file > if @file_data > File.makedirs("#{ALBUM_COVER_STORAGE_PATH}/#{id}") > File.open("#{ALBUM_COVER_STORAGE_PATH}/#{id}/#{id}.#{extension}", "w") { > |file| file.write(@file_data.read) } > # put calls to other logic here - resizing, conversion etc. > end > end > > In that example, your current object _is_ the model. You could write self, for > example, and get your model''s attributes. > > To update, use update_attribute like this: > > self.update_attribute :cover, "#{id}.#{extension}" > > However, I don''t know if that will infinitely recurse, because you are inside an > after_save event. Does update trigger another after_save event?--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I am receiving this error undefined method `original_filename'' for "10.png":String when trying this: def write_file if @file_data File.makedirs("#{LOGO_PATH}/#{id}") File.open("#{LOGO_PATH}/#{id}/#{id}.#{extension}", "w") { |file| file.write(@file_data.read) } # put calls to other logic here - resizing, conversion etc. self.update_attribute :logo, "#{id}.#{extension}" end end def extension @file_data.original_filename.split(".").last end Any ideas why? On May 25, 9:42 am, yaphi <jconto...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thanks for the reply! > > Yes update triggers an after_save because I can overwrite the image by > editing it. I will try this, thank you very much. > > On May 25, 2:05 am, Phlip <phlip2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > yaphi wrote: > > > So I am following the directions on the RoR wiki for uploading images > > > (the new 2.0.2 directions) :http://wiki.rubyonrails.org/rails/pages/HowtoUploadFiles > > > > The files upload beautifully, but I don''t know how to access the > > > images since it''s not inserting the file name into "cover" when the > > > file posts. It leaves it null. How can I say: > > > > def write_file > > > if @file_data > > > ... > > > ... > > > ... > > > set cover to "#{id}.#{extension}" > > > end > > > end > > > You mean this? > > > def write_file > > if @file_data > > File.makedirs("#{ALBUM_COVER_STORAGE_PATH}/#{id}") > > File.open("#{ALBUM_COVER_STORAGE_PATH}/#{id}/#{id}.#{extension}", "w") { > > |file| file.write(@file_data.read) } > > # put calls to other logic here - resizing, conversion etc. > > end > > end > > > In that example, your current object _is_ the model. You could write self, for > > example, and get your model''s attributes. > > > To update, use update_attribute like this: > > > self.update_attribute :cover, "#{id}.#{extension}" > > > However, I don''t know if that will infinitely recurse, because you are inside an > > after_save event. Does update trigger another after_save event?--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
yaphi wrote:> I am receiving this error > undefined method `original_filename'' for "10.png":String > > when trying this: > > def write_file > if @file_data > File.makedirs("#{LOGO_PATH}/#{id}") > File.open("#{LOGO_PATH}/#{id}/#{id}.#{extension}", "w") { |file| > file.write(@file_data.read) } > # put calls to other logic here - resizing, conversion etc. > self.update_attribute :logo, "#{id}.#{extension}" > end > end > > def extension > @file_data.original_filename.split(".").last > end > > Any ideas why?@file_data is the object that is complaining. You think its an uploaded file object, but according to that error, its a "10.png":String. This is a common problem with your form. If you leave off the :html => { :multipart => true } in your form tag, then your browser will only send the filename, not the actual data. <%= form_tag @photo, :html => { :multipart => true } do |f| %> I think. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hey Alex, Uploading the file is not my problem. The problem is adding the: self.update_attribute :logo, "#{id}.#{extension}" to the write_file method. I want the file to upload (which it does), then I want it to insert the filename into the logo column of the table. On May 28, 1:28 pm, Alex Wayne <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> yaphi wrote: > > I am receiving this error > > undefined method `original_filename'' for "10.png":String > > > when trying this: > > > def write_file > > if @file_data > > File.makedirs("#{LOGO_PATH}/#{id}") > > File.open("#{LOGO_PATH}/#{id}/#{id}.#{extension}", "w") { |file| > > file.write(@file_data.read) } > > # put calls to other logic here - resizing, conversion etc. > > self.update_attribute :logo, "#{id}.#{extension}" > > end > > end > > > def extension > > @file_data.original_filename.split(".").last > > end > > > Any ideas why? > > @file_data is the object that is complaining. You think its an uploaded > file object, but according to that error, its a "10.png":String. This > is a common problem with your form. If you leave off the :html => { > :multipart => true } in your form tag, then your browser will only send > the filename, not the actual data. > > <%= form_tag @photo, :html => { :multipart => true } do |f| %> > > I think. > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
yaphi wrote:> Hey Alex, > > Uploading the file is not my problem. The problem is adding the: > > self.update_attribute :logo, "#{id}.#{extension}" > > to the write_file method. I want the file to upload (which it does), > then I want it to insert the filename into the logo column of the > table. > > On May 28, 1:28�pm, Alex Wayne <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>Well, if the exception is: undefined method `original_filename'' for "10.png":String And the only place your calling the method original_filename is here: def extension @file_data.original_filename.split(".").last end Then @file_data is the string "10.png", not a file object. Look wherever you are assigning that instance variable. It won''t have an original_filename method unless its actually an uploaded file. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---