Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何销毁rails嵌套表单中的空字段_Ruby On Rails - Fatal编程技术网

Ruby on rails 如何销毁rails嵌套表单中的空字段

Ruby on rails 如何销毁rails嵌套表单中的空字段,ruby-on-rails,Ruby On Rails,如何在rails中使用“reject_if”。并销毁空字段或空白字段 我用的是这行代码 accepts_nested_attributes_for :user_twitter_reals,:allow_destroy => true, :reject_if => lambda { |a| a.destroy if a[:twitter_url].blank? }#,reject_if:proc { |user_twitter_reals_attributes| attributes

如何在rails中使用“reject_if”。并销毁空字段或空白字段

我用的是这行代码

 accepts_nested_attributes_for :user_twitter_reals,:allow_destroy => true, :reject_if => lambda { |a| a.destroy if a[:twitter_url].blank? }#,reject_if:proc { |user_twitter_reals_attributes| attributes.all? { |key, value| key == '_destroy' || value.blank? } }
  accepts_nested_attributes_for :user_twitter_chipcounts,:allow_destroy => true, :reject_if => lambda { |a| a[:twitter_url].blank? }
  accepts_nested_attributes_for :user_twitter_fakes,:allow_destroy => true, :reject_if => lambda { |a| a[:twitter_url].blank? }
  accepts_nested_attributes_for :user_cells,:allow_destroy => true, :reject_if => lambda { |a| a[:cell_number].blank? }
  accepts_nested_attributes_for :user_facebook_personals,:allow_destroy => true, :reject_if => lambda { |a| a[:facebook_url].blank? } 
  accepts_nested_attributes_for :user_facebook_fansites,:allow_destroy => true, :reject_if => lambda { |a| a[:facebook_url].blank? } 
  accepts_nested_attributes_for :user_facebook_fakes,:allow_destroy => true, :reject_if => lambda { |a| a[:facebook_url].blank? } 
  accepts_nested_attributes_for :user_social_account 
  accepts_nested_attributes_for :user_websitess,:allow_destroy => true, :reject_if => lambda { |a| a[:site_url].blank? } 
  accepts_nested_attributes_for :user_wikipedias,:allow_destroy => true, :reject_if => lambda { |a| a[:wikipidea_url].blank? } 
  accepts_nested_attributes_for :user_imdbs,:allow_destroy => true, :reject_if => lambda { |a| a[:imdburl].blank? } 
  accepts_nested_attributes_for :user_googlepluss,:allow_destroy => true, :reject_if => lambda { |a| a[:gooplus_url].blank? } 
  accepts_nested_attributes_for :user_youtubes,:allow_destroy => true, :reject_if => lambda { |a| a[:youtube_url].blank? } 
  accepts_nested_attributes_for :user_myspaces,:allow_destroy => true, :reject_if => lambda { |a| a[:myspace_url].blank? } 
  accepts_nested_attributes_for :user_linkedins,:allow_destroy => true, :reject_if => lambda { |a| a[:linkedin_url].blank? } 
  accepts_nested_attributes_for :user_pinterests,:allow_destroy => true, :reject_if => lambda { |a| a[:pinterest_url].blank? } 
  accepts_nested_attributes_for :usersetting,:allow_destroy => true
试一试

对其他人也一样
接受:user的_嵌套的_属性_,如果=>proc{| attributes | attributes['password']。blank?}

请对嵌套属性执行相同的操作

如果所有属性都为空,则将其视为拒绝

accepts_nested_attributes_for :location, :reject_if => :all_blank, :allow_destroy => true

请参考

,但我如何在编辑表单上处理它,我们将其设置为空白。
accepts_nested_attributes_for :location, :reject_if => :all_blank, :allow_destroy => true