如何删除空白嵌套表单字段?

时间:2014-06-20 06:55:03

标签: ruby-on-rails

我如何在rails中使用此代码拒绝嵌套表单中的空白嵌套字段:

class Award < ActiveRecord::Base
  attr_accessible :category, :country_iso,:title, :year,:status ,:nomination_awards_attributes,:sponsor_awards_attributes,:city
  has_many :nomination_awards, dependent: :destroy
  has_many :sponsor_awards, dependent: :destroy


  accepts_nested_attributes_for :nomination_awards, :allow_destroy => true
  accepts_nested_attributes_for :sponsor_awards, :allow_destroy => true#,:reject_if => lambda { |a| a[:sponsor_id].blank? }
  validates :title,:category,:country_iso,:year,:city, :presence => true


end

1 个答案:

答案 0 :(得分:0)

使用此代码拒绝空白字段 :reject_if =&gt; lambda {| a |一个[:sponsor_id] .blank? }

并且是否存在编辑数据,如果数据存在或构建我们不需要在编辑页面中构建(如果不存在或构建)我们必须在编辑页面上构建....