Mano
Mano

Reputation: 987

Carrierwave undefined method `avatar_changed?' for User

I use carrierwave gem for uploading image.I use attr_accessor: avatar in my model.I don't want to create the database column. I can store avatar in the particular directory.But when i update_attribute for some other field, i am getting undefined method undefined methodavatar_changed?' for User`. Am i missing anything here? Help me to solve this. This is my User model

 attr_accessor: avatar
 mount_uploader: avatar, AvatarUploader

AvatarUploader < IconBase
  DIEMENSIONS=[120,120]

  def filename
    "avatar.png"
  end
end

Upvotes: 7

Views: 3493

Answers (1)

Andrey Sereda
Andrey Sereda

Reputation: 204

If you use mount_uploader: avatar, AvatarUploader you should create database columns. IF you do not want to add columns, you should not mount an Uploader, but rather work with things like that:

uploader = AvatarUploader.new
uploader.store!(my_file)
uploader.retrieve_from_store!('my_file.png')

Upvotes: 9

Related Questions