undefined method `stringify_keys'

邮差的信 提交于 2019-12-12 07:39:14

问题


When I try to upload image using Paperclip gem I got this error:

NoMethodError (undefined method `stringify_keys' for <ActionDispatch::Http::UploadedFile:0x000000025387f0>)

class MenuItem < ActiveRecord::Base
 has_one :image


end

class Image < ActiveRecord::Base
 belongs_to :menu_item
 has_attached_file :image, :styles => {
            :large => "640x480",
            :medium => "300x300", 
            :thumb => "100x100" 
           }
end

回答1:


I've seen this error happen before, usually when people attempt to call update_attributes like this:

update_attributes(params[:image])

The call should actually be this:

update_attributes(:image => params[:image])

A bit of a shot in the dark, but if that's it I'm sure we'll all be impressed.




回答2:


After struggling for a while in rails 3.2.2 I managed to solve this in this manner

(image = Image.new(image: params[:image])).save

update_attributes(image: image)




回答3:


I just had this problem, and to clarify things a bit, update_attributes is different from update_attribute.

The following should work:

update_attributes(:image => params[:image])

or

update_attribute(:image, params[:image])

There you go! There are other issues with update_attributes related to attr_accesible, but either works.



来源:https://stackoverflow.com/questions/8514970/undefined-method-stringify-keys

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!