【发布时间】:2017-10-26 05:41:50
【问题描述】:
我有两个模型
class ComfortFactorSubCategory < ApplicationRecord
has_one :image, as: :imageable, dependent: :destroy
validates :heading, presence: true
accepts_nested_attributes_for :image, :reject_if => lambda { |a| a[:name].blank? }, allow_destroy: true
end
class Image < ApplicationRecord
belongs_to :imageable, polymorphic: true
mount_uploader :name, IconUploader
end
我的管理员/comfort_factor_sub_category.rb 我有这些行
ActiveAdmin.register ComfortFactorSubCategory do
permit_params do
permitted = [:heading, image_attributes: [:name, :_destroy, :id], additional_instruction_ids: []]
permitted
end
form do |f|
f.inputs do
f.input :heading
f.input :additional_instructions, as: :select, collection: AdditionalInstruction.pluck(:description, :id)
f.fields_for :image do |b|
b.input :name, label: "Image", :as => :file
end
end
f.actions
end
end
当我提交带有错误信息的表单时,可以说没有标题并且验证失败,为什么我在第一次提交时确实需要再次选择图像
【问题讨论】:
标签: ruby-on-rails activerecord activeadmin carrierwave polymorphic-associations