私はacts_as_taggable_ongemを使用して広告にタグを付けています。正常に動作しますが、画像を含めるためにタグが必要なので、プラグインを拡張してこのモジュールを作成することにしました。
# 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
これに関する提案はありますか?