我正在使用acts_as_taggable_on gem 来标记广告。它工作正常,但我需要标签有图像,所以我决定扩展插件并编写这个模块:
# Add logic to ActsAsTaggableOn Tag model
module TagExtend
def self.included(recipient)
recipient.extend(ClassMethods)
end
module ClassMethods
ActiveRecord::Base.attr_accessible :tag_image
ActiveRecord::Base.has_attached_file :tag_image,
:styles => { :medium => "300x200>"},
:storage => :s3,
:bucket => S3_BUCKET,
:s3_host_name => S3_HOST,
:s3_credentials => {
:access_key_id => S3_KEY,
:secret_access_key =>S3_SECRET
}
end
end
在初始化文件中:
require File.dirname(__FILE__) + '/../../lib/tag_extend.rb'
ActsAsTaggableOn::Tag.send(:include, TagExtend)
它应该可以工作,但是当我尝试使用图像(来自 ActiveAdmin)保存标签时,我得到:Can't mass-assign protected attributes: tag_image
对此有什么建议吗?