[英]accepts_nested_attributes_for :reject_if to trigger another method
[英]custom attributes version of accepts_nested_attributes_for with reject_if
我試圖在下面創建一個自定義版本
accepts_nested_attributes_for :categories, :reject_if => proc { |hash| hash['title'].blank? }
到目前為止,我得到的是
def categories_attributes=(categories_attributes)
categories_attributes.values.each do |category_attribute|
category = Category.find_or_create_by(category_attribute)
categories << category
end
end
但是我試圖在其中添加reject_if部分,我似乎無法弄清楚。 我如何將該部分復制到下面的自定義屬性中?
謝謝!
這樣做
accepts_nested_attributes_for :categories, reject_if: :title_blank
def title_blank(attributed)
data = false
data = true if attributed.title.blank?
return data
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.