我有一个 Active Admin 模型,:gallery,它有一个嵌套的回形针资源,:images。 :gallery has_many :images。
:gallery 有一个字段,:title,这是必需的。
当我在没有标题的情况下提交时,其他字段仍然存在(:描述,:位置),但嵌套资源变为空白。
有没有办法在验证之前构建资源,以便在验证检查失败后它仍然存在?
f.inputs "Images" do
f.has_many :images do |i|
i.input :image,
:as=>:file,
:multipart => true,
:label => "Image"
end
end
最佳答案
请检查您是否在 中添加了这些必需的东西画廊 模型
attr_accessible :images_attributes
和
accepts_nested_attributes_for :images, :allow_destroy => :true
关于ruby-on-rails - 事件管理员 before_validation Hook ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13455634/