rubyruby-on-rails-3activerecordcarrierwaverails-activerecord

Manually updating attributes mounted by Carrierwave Uploader


I am unable to use model.update_attribute on an attribute that is mounted by a carrierwave uploader. The SQL statement wont accept the value and adds NULL to the placeholder. If I remove the mount_uploader statement from the model class it works as normal. I am troubleshooting things from the console and trying to add some attributes while seeding the DB and this is thwarting my efforts. Ideas?

Thanks.

Update: Relevant code:

class Profile < ActiveRecord::Base
  belongs_to :user
  has_and_belongs_to_many :sports
  has_and_belongs_to_many :interests
  has_and_belongs_to_many :minors
  has_and_belongs_to_many :majors
  has_and_belongs_to_many :events
  has_and_belongs_to_many :groups
  attr_accessible :description, :username, :avatar, :bio, :first_name, :last_name, :major, :minor, :graduation_date, :living_situation, :phone, :major_ids, :minor_ids, :sport_ids
  mount_uploader :avatar, AvatarUploader
end

I am simply trying to rewrite the :avatar string from a db seed file and while testing from the rails console like so: Profile.first.update_attribute(:avatar, 'foo')

Both work when I comment out the mount_uploader line.

Does adding the mount_uploader method freeze the string or make it immutable?


Solution

  • I found a solution to this.

    My issue was that I was not able to alter the attribute mounted my the CarrierWave uploader from my seeds.rb file.

    This works:

    user.profile.update_column(:avatar, 'foobar/image.png')