加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 活动管理员before_validation挂钩?

发布时间:2020-12-17 02:03:27 所属栏目:百科 来源:网络整理
导读:我有一个Active Admin模型,:gallery,它有一个嵌套的回形针资源,:images. :gallery has_many:图片. :gallery有一个字段,:title,这是必需的. 当我提交没有标题时,其他字段仍然存在(:description,:location),但嵌套资源变为空白. 有没有办法在验证之前
我有一个Active Admin模型,:gallery,它有一个嵌套的回形针资源,:images. :gallery has_many:图片.

:gallery有一个字段,:title,这是必需的.

当我提交没有标题时,其他字段仍然存在(:description,:location),但嵌套资源变为空白.

有没有办法在验证之前构建资源,以便在验证失败后它仍然存在?

f.inputs "Images" do 
      f.has_many :images do |i| 

          i.input :image,:as=>:file,:multipart => true,:label => "Image" 
              end
    end

解决方法

请检查您是否在Gallery模型中添加了这些必需的内容

attr_accessible :images_attributes

accepts_nested_attributes_for :images,:allow_destroy => :true

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读