Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undefined method `stringify_keys'

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 
like image 811
user908798 Avatar asked Dec 15 '11 04:12

user908798


2 Answers

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.

like image 184
Ryan Bigg Avatar answered Oct 08 '22 17:10

Ryan Bigg


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)

like image 21
Sagish Avatar answered Oct 08 '22 16:10

Sagish