我如何在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
答案 0 :(得分:0)
使用此代码拒绝空白字段 :reject_if =&gt; lambda {| a |一个[:sponsor_id] .blank? }
并且是否存在编辑数据,如果数据存在或构建我们不需要在编辑页面中构建(如果不存在或构建)我们必须在编辑页面上构建....