Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 495
Mano Avatar asked Nov 29 '13 12:11

Mano


1 Answers

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')
like image 65
Andrey Sereda Avatar answered Nov 07 '22 04:11

Andrey Sereda