ruby-on-rails-4 – ActiveAdmin复制嵌套表单并删除复选框不起作
发布时间:2020-12-17 03:07:15 所属栏目:百科 来源:网络整理
导读:该表单用于向项目添加项目,但项目不会删除!更糟糕的是,任何更新都会复制所有嵌套表单(1×2 = 2,然后下一次更新为每个更新4等) 应用程序/管理/ project.rb ActiveAdmin.register Project do permit_params :title,:description,:git_url,:demo_url,:version,
该表单用于向项目添加项目,但项目不会删除!更糟糕的是,任何更新都会复制所有嵌套表单(1×2 = 2,然后下一次更新为每个更新4等)
应用程序/管理/ project.rb ActiveAdmin.register Project do permit_params :title,:description,:git_url,:demo_url,:version,:lastpublished,:firstpublished,project_features_attributes: [:project_id,:_destroy => true],project_mentions_attributes: [:project_id,:title,:url,:published,:_destroy => true] form do |f| f.semantic_errors *f.object.errors.keys f.inputs f.buttons end form do |f| f.inputs "Project Details" do f.inputs :title f.inputs :description f.inputs :git_url,:default => "http://github.com/" f.inputs :demo_url f.inputs :version f.inputs :firstpublished f.inputs :lastpublished f.inputs do f.has_many :project_features,:allow_destroy => true,:heading => 'Features' do |cf| cf.input :description end end f.inputs do f.has_many :project_mentions,:heading => 'Mentions' do |cf| cf.input :title cf.input :url cf.input :published end end end f.actions end end 应用程序/模型/ project.rb class Project < ActiveRecord::Base has_many :project_features,:dependent => :destroy accepts_nested_attributes_for :project_features,:reject_if => lambda{ |a| a[:description.blank?] },:allow_destroy => true has_many :project_mentions,:dependent => :destroy accepts_nested_attributes_for :project_mentions,:reject_if => lambda{ |a| a[:title.blank?] },:allow_destroy => true has_many :blogs end 应用程序/模型/ project_feature.rb class ProjectFeature < ActiveRecord::Base belongs_to :project end 应用程序/模型/ project_feature.rb class ProjectMention < ActiveRecord::Base belongs_to :project end 解决方法
尝试:_destroy而不是:_destroy =>在permit_params块中为true.
复制:删除公用文件夹的内容.在开发模式下,您不必预编译资产. 更新:您必须允许相关记录的ID: project_features_attributes: [:id,:project_id,:_destroy],project_mentions_attributes: [:id,:_destroy] (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |