# \[help\] problem uploading file... w stringifykey!

**URL:** <https://www.ruby-forum.com/t/help-problem-uploading-file-w-stringifykey/112611>\
**Category:** Rails\
**Created:** [August 21, 2007, 12:01pm UTC](https://www.ruby-forum.com/t/help-problem-uploading-file-w-stringifykey/112611 "2007-08-21T12:01:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kadoudal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f0a364/32.png) [@kadoudal](https://www.ruby-forum.com/u/kadoudal)\
**Post date:** [August 21, 2007, 12:01pm UTC](https://www.ruby-forum.com/t/help-problem-uploading-file-w-stringifykey/112611/1 "2007-08-21T12:01:57Z")

</div>

I am uploading an image the standard way…

advertising edit view

.... ..

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…

---

<div class="post-metadata">

**Author:** ![kadoudal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f0a364/32.png) [@kadoudal](https://www.ruby-forum.com/u/kadoudal)\
**Post date:** [August 21, 2007, 12:07pm UTC](https://www.ruby-forum.com/t/help-problem-uploading-file-w-stringifykey/112611/2 "2007-08-21T12:07:38Z")

</div>

i think this method

def get\_file  
send\_file(params[:file])  
end

is missing check it out

---

<div class="post-metadata">

**Author:** ![kadoudal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f0a364/32.png) [@kadoudal](https://www.ruby-forum.com/u/kadoudal)\
**Post date:** [August 21, 2007, 12:47pm UTC](https://www.ruby-forum.com/t/help-problem-uploading-file-w-stringifykey/112611/3 "2007-08-21T12:47:34Z")

</div>

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](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](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

---

<div class="post-metadata">

**Author:** ![kadoudal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f0a364/32.png) [@kadoudal](https://www.ruby-forum.com/u/kadoudal)\
**Post date:** [August 21, 2007, 2:31pm UTC](https://www.ruby-forum.com/t/help-problem-uploading-file-w-stringifykey/112611/4 "2007-08-21T14:31:58Z")

</div>

Shai R. 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](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](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

thanks 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
