Question

Im using Dragonfly and Amazon s3 for the image uploads. For some reason when I upload a picture, it saves to the right folder on amazon, and the uid is the right path, but it is not showing up!

Every time I call user.avatar it is nil even though user.avatar_uid is correct. How can I get the image to display properly with user.avatar.remote_url?

class User < ActiveRecord::Base

  image_accessor :avatar do
    storage_path { |file| 
      "#{self[:id]}/avatar/pic#{rand(1000)}.#{file.format.to_s.downcase}" 
    }
    after_assign { |a| 
      self.avatar = a.jpg.thumb('300x300#n') if (VALID_PHOTO_TYPES.include? self.avatar.format)
    }
  end  

  attr_accessible :avatar_url, :retained_avatar, :avatar
  attr_reader :id, :avatar_uid
Was it helpful?

Solution

The problem is the :avatar_uid in any of attr_reader, attr_writer, attr_accessible.

If you have that in your model, it will break. Pretend that the *_uid does not exist for any model with Dragonfly and only use user.avatar.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top