Rails activeadmin / carrierwave has_many照片关系投掷质量分配异常

时间:2014-09-02 01:54:09

标签: ruby-on-rails activerecord activeadmin carrierwave mass-assignment

我将模型BlogPost定义为

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

来自架构

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

和一个activeadmin表单来创建一个新的博客帖子

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

我也使用carrierwave将照片上传到S3。使用所有这些代码,当我尝试在活动管理员中创建一个新的博客帖子时,我收到一个批量分配错误说: 无法批量分配受保护的属性:title,body,photos_attributes

但是,你可以看到我已经非常清楚地列出了这些属性,那么可能是什么造成了这个?

编辑:包含在

行之后
class BlogPost < ActiveRecord::Base
  mount_uploader :photo, BlogPhotoUploader

现在异常是

undefined method `validate_integrity' for :BlogImageUploader:Symbol

0 个答案:

没有答案