手动更新安装由Carrierwave上传属性 [英] Manually updating attributes mounted by Carrierwave Uploader
问题描述
我无法使用model.update_attribute上安装由carrierwave上传的属性。 SQL语句不会接受该值,并增加了空的占位符。如果我从模型类中删除mount_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?
感谢。
更新: 相关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
我只是想重写:从数据库种子文件的头像字符串,而从像这样的轨道控制台测试: Profile.first.update_attribute(:头像,'富')
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')
当我注释掉mount_uploader线两者的工作。
Both work when I comment out the mount_uploader line.
是否加入mount_uploader方法冻结字符串或使之不可变的?
Does adding the mount_uploader method freeze the string or make it immutable?
推荐答案
我找到了解决这个。
我的问题是,我是不是能够改变属性安装我的CarrierWave上传从我seeds.rb文件。
My issue was that I was not able to alter the attribute mounted my the CarrierWave uploader from my seeds.rb file.
本作品:
user.profile.update_column(:avatar, 'foobar/image.png')
这篇关于手动更新安装由Carrierwave上传属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!