问题
I have a model BlogPost defined as
class BlogPost < ActiveRecord::Base
attr_accessible :title, :body, :photo, :photos_attributes, as: :admin
has_many :photos, class_name: 'BlogPhoto', dependent: :destroy
validates :body, :photo, :title, presence: true
validates :title, uniqueness: true
accepts_nested_attributes_for :photos, allow_destroy: true
end
from schema
create_table "blog_posts", :force => true do |t|
t.string "title"
t.text "body"
t.datetime "created_at", :null => false
t.string "photo"
t.datetime "updated_at", :null => false
end
class BlogPhoto < ActiveRecord::Base
belongs_to :blog_post
attr_accessible :photo, as: :admin
mount_uploader :photo, BlogPhotoUploader
end
and an activeadmin form to create a new blogpost
form do |f|
f.inputs "Blog Post" do
f.input :title
f.input :body, as: :html_editor
end
f.inputs "Photos" do
f.has_many :photos do |p|
p.input :photo, as: :file
p.input :_destroy, as: :boolean, required: false, label: 'Remove Photo'
end
end
f.actions
end
I am also using carrierwave to upload photos to S3. With all of thise code, when I try to create a new blogpost inside of active admin, I get a mass-assignment error saying: Can't mass-assign protected attributes: title, body, photos_attributes
However, you can see I've very clearly white-listed those attributes, so what could be causing this?
EDIT: Included following line to
class BlogPost < ActiveRecord::Base
mount_uploader :photo, BlogPhotoUploader
and now the exception is
undefined method `validate_integrity' for :BlogImageUploader:Symbol
来源:https://stackoverflow.com/questions/25614802/rails-activeadmin-carrierwave-has-many-photos-relationship-throwing-mass-assignm