나는 광고에 태그를 쓸 때 acts_as_taggable_on 보석을 사용하고 있습니다. 그것은 잘 작동하지만 나는 이미지를 가질 태그가 필요합니다, 그래서 플러그인을 확장하기로 결정하고이 모듈 writed :ActsAsTaggableOn을 확장하여 이미지가 있지만 "보호 된 속성을 대량 지정할 수 없습니다 : tag_image"오류가 발생했습니다.
# 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
이 문제에 대한 제안이 있으십니까?
내 문제가 해결되었습니다. 신경 쓰지 마라, 나는 기본 클래스에서 attr_accessible을 호출해야한다고 생각했다. 답변 해주셔서 감사합니다 !! – cicloon
이것은 모든 모델 클래스에 대해 액세스 할 수있는 특성의 배열이 하나 뿐인 것을 의미합니다. 그것은 잘 작동하지 않을 것입니다. – phoet