Manually updating attributes set by the Carrierwave loader

I cannot use model.update_attribute for the attribute set by the carrier loader. The SQL statement does not take a value and adds NULL to the placeholder. If I remove the mount_uploader statement from the model class, it will work fine. I am parsing things from the console and trying to add some attributes when sowing the database, and this interferes with my efforts. Ideas?

Thanks.

Update: Corresponding 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'm just trying to rewrite the line: avatar from the db sample file and when testing from the rails console as follows: Profile .first.update_attribute (: avatar, 'foo')

Both work when I comment on the mount_uploader line.

Does the mount_uploader method add a line freeze or make it immutable?

+6
source share
1 answer

I have found a solution to this.

My problem was that I could not change the attribute set by my CarrierWave loader from the seeds.rb file.

It works:

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

Source: https://habr.com/ru/post/954372/


All Articles