Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

model missing required attr_accessor for 'photo_file_name' when uploading with paperclip and S3 on heroku

Setting up paperclip with S3 in my linux dev environment was a snap -- everything works out of the box. However, I can't get it to work on Heroku.

When I try to do an upload, the log shows:

Processing ItemsController#create (for 72.177.97.9 at 2010-08-26 16:35:14) [POST]  
  Parameters: {"commit"=>"Create", "authenticity_token"=>"0Hy3qvQBHE1gvFVaq32HMy2ZIopelV0BHbrSeHkO1Qw=", "item"=>{"photo"=>#<File:/home/slugs/270862_4aa601b_4b6f/mnt/tmp/RackMultipart20100826-6286-1256pvc-0>, "price"=>"342", "name"=>"a new item", "description"=>"a new item", "sold"=>"0"}}

Paperclip::PaperclipError (Item model missing required attr_accessor for 'photo_file_name'):

I found one blog post that referenced this error, and it said to add this to my model:

attr_accessor :photo_file_name
attr_accessor :photo_content_type
attr_accessor :photo_file_size
attr_accessor :photo_updated_at

That does indeed make the model missing required attr_accessor for 'photo_file_name' error go away, but it still doesn't work. See my other question for details. As I have figured out that with the attr_accessor lines added to my model the uploads fail even on my dev system, I suspect that is not the right answer.

like image 541
eksatx Avatar asked Aug 27 '10 00:08

eksatx


3 Answers

Found the problem: needed to update the database.

heroku run rake:db:migrate

heroku restart

I had done what I thought would have accomplished the same thing already:

heroku rake db:schema:load

but perhaps that doesn't work or something went wrong in the process.

like image 178
eksatx Avatar answered Nov 02 '22 14:11

eksatx


Error like this occurs if you create wrong column type in migration. When you define new table migration for paperclip, you need to specify t.attachment :name insted of t.string :name. Or add_attachment :table, :name when you add new paperclip column in existed table. And now you don't need to add these attributes in attr_accessor in model.

like image 27
jarosluv Avatar answered Nov 02 '22 13:11

jarosluv


Well, this message seems to be because the columns it's missing. Try create a migration creating the columns:

class AddPhotoToEvent < ActiveRecord::Migration
  def change
    add_column :events, :photo_file_name,    :string
    add_column :events, :photo_content_type, :string
    add_column :events, :photo_file_size,    :integer
    add_column :events, :photo_updated_at,   :datetime
  end

end

This work for me, here i have a table events with photo

like image 21
Alexandre Magno Teles Zimerer Avatar answered Nov 02 '22 12:11

Alexandre Magno Teles Zimerer