我有一个嵌套表单,其中每个帖子都有很多位置。问题是,如果用户创建了一个位置,然后将其留空,它会用空白数据填充我的表。
我认为这会在我的post.rb
模型中做到这一点:
accepts_nested_attributes_for :locations, :allow_destroy => true, :reject_if => proc { |attributes| attributes['name'].blank? }
但是它们仍然在空白时滑过并被保存。知道为什么吗?
编辑:这是评论中要求的哈希:
Parameters: {"utf8"=>"✓","authenticity_token"=>"r74iCzC4tJgVI6FiCEH7XzfiTmaqKihF5JSs7Ow3MSI=", "post"=>{"title"=>"This is a test blog post fo
r stack overflow", "body"=>"This is a test blog post for stack overflow", "tag_list"=>"", "locations_attributes"=>{"0"=>{"name"=>"London", "long
itude"=>"-0.1276831", "latitude"=>"51.5073346"}, "1354382846976"=>{"name"=>"Paris", "longitude"=>"2.3522219", "latitude"=>"48.856614"}, "1354382
849464"=>{"name"=>"", "longitude"=>"", "latitude"=>""}, "1354382850624"=>{"name"=>"", "longitude"=>"", "latitude"=>""}}}, "_wysihtml5_mode"=>"1"
, "name"=>"", "legname"=>"Paris", "longitude"=>"2.3522219", "latitude"=>"48.856614", "commit"=>"Submit"}