0

I am using paperclip at attach images to offers in my rails application. The code works in development, but not in staging. In staging, the images are saving correctly to s3, but the image_file_name is nil.

db/migrate/20130507182116_add_image_to_offers.rb

class AddImageToOffers < ActiveRecord::Migration
  def self.up
    add_attachment :offers, :image
  end

  def self.down
    remove_attachment :offers, :image
  end
end

app/models/offer.rb

class Offer < ActiveRecord::Base
  attr_accessor :image

  has_attached_file :image, styles: {
    thumb: '100x100>',
    square: '200x200#',
    medium: '300x300>'
  }

When I run the following configuration in development mode it works, when I switch to staging I get the following error:

Paperclip::Error (Offer model missing required attr_accessor for 'image_file_name'):

If I add attr_accessor :image_file_name to the model it completes and the image saves to s3, but the attribute is nil in the database.

dysbulic
  • 3,005
  • 2
  • 28
  • 48

1 Answers1

1

Be sure to migrate your database. Also, if you're using heroku you'll need to restart the service: model missing required attr_accessor for 'photo_file_name' when uploading with paperclip and S3 on heroku

Community
  • 1
  • 1
Marek Takac
  • 3,002
  • 25
  • 30