I am uploading an image the standard way... advertising edit view <form action="/user/advertisings/5" enctype="multipart/form-data" method="post"> <input name="_method" type="hidden" value="put" /></div> .... <input id="file_data" name="file_data" size="40" type="file" /> .. <input class="inputSubmit" name="commit" type="submit" value="Modify" /> </form> my controller try to create the image..... advertising_controller def update ... @illustration = Illustration.new(params[:file_data]) .. @illustration.save ... end from the Illustration model... .. attr_accessor :file_data ... def file_data=(file_data) @file_name = sanitize_filename(@file_data.original_filename) # windows trick write_attribute ''extension'', @file_name.split(''.'').last.downcase end ... the request parameters : "_method"=>"put", "id"=>"5", "file_data"=>#<File:/tmp/CGI29555.9>.... but I always get an error : NoMethodError (undefined method `stringify_keys!'' for #<File:/tmp/CGI29555.9>): /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/base.rb:1669:in `attributes='' the problem is actually in passing the params[:file_data], as using @illustration = Illustration.new is OK.... 1- what''s this ActiveRecord error `stringify_keys!'' 2- what''s wrong with my param ? cannot even get into the file_data method ? thanks a lot for your help... I am stuck for 2 days on this problem.... -- 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 -~----------~----~----~----~------~----~------~--~---
i think this method def get_file send_file(params[:file]) end is missing check it out -- 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 -~----------~----~----~----~------~----~------~--~---
small background: "stringify_keys!" errors usually are populated because of some bad usage with hashes: basically, a key of the hash is supposed to be ''stringified'' to_s of some sort, but it cannot, because there is no way to ''stringify'' that key. look at http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Hash/Keys.html#M000365 say, as an example, if it u had a hash like {:controller => ''some'', :action =>''thing''} it would become {"controller" => ''some'', "action" =>''thing''} after using the stringify_keys! method. but, if you have a hash that has keys that cannot be ''stringified'', you''ll get this error. in our case, my guess would be #<File:/tmp/CGI29555.9> is causing an error. maybe it is trying to create a hash out of that object, (while changing it to a params[:file_data] ) but fails as it is a picture / no method to stringify the key of this object exists ... any special reason u don''t use some rails plugin for uploading pics? just googling for a sec, i found http://www.flex888.com/2007/03/21/three-ruby-on-rails-file-upload-plugins-reviewed.html and i''ve heard good things about acts_as_attachment (although i haven''t personally used it). anyway, hope this helps out. shai -- 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 -~----------~----~----~----~------~----~------~--~---
Shai Rosenfeld wrote:> small background: > > "stringify_keys!" errors usually are populated because of some bad usage > with hashes: > > basically, a key of the hash is supposed to be ''stringified'' to_s of > some sort, but it cannot, because there is no way to ''stringify'' that > key. > look at > > http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Hash/Keys.html#M000365 > > say, as an example, if it u had a hash like > {:controller => ''some'', :action =>''thing''} > it would become > {"controller" => ''some'', "action" =>''thing''} > after using the stringify_keys! method. > > but, if you have a hash that has keys that cannot be ''stringified'', > you''ll get this error. in our case, my guess would be > > #<File:/tmp/CGI29555.9> > > is causing an error. maybe it is trying to create a hash out of that > object, (while changing it to a params[:file_data] ) but fails as it is > a picture / no method to stringify the key of this object exists ... > > any special reason u don''t use some rails plugin for uploading pics? > just googling for a sec, i found > > http://www.flex888.com/2007/03/21/three-ruby-on-rails-file-upload-plugins-reviewed.html > > and i''ve heard good things about acts_as_attachment (although i haven''t > personally used it). > > anyway, hope this helps out. > > shaithanks a lot for doc links... I already gave a look at the plugins... but actually I don''t need all their features, so I am using the standard Rails'' cookbook indications.. writing in my controller @illustration = Illustration.new @illustration.uploaded_file = params[:illustration][:file_data] and attr_accessor :file_data def uploaded_file=(incoming_file) self.file_name = incoming_file.original_filename self.file_data = incoming_file write_attribute ''extension'', self.file_name.split(''.'').last.downcase end makes things running well.... need (later) to understand why ... kad -- 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 -~----------~----~----~----~------~----~------~--~---