1

私はこれまでのところ、私が得たものカスタムは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のバージョン属性私はそれを理解しているようです。その部分を下のカスタム属性にどのように複製できますか?

ありがとうございます!

答えて

0

私はカスタムを使用しようとしていますこのよう

accepts_nested_attributes_for :categories, reject_if: :title_blank 

def title_blank(attributed) 
    data = false 
    data = true if attributed.title.blank? 
    return data 
end 
+0

として行いますがaccepts_nested_attributes_for thatsのは –

+0

私はイムは、カスタムバージョンにそれを複製しようと、作品を投稿accepts_nested_attributes_forのバージョンレールに含まれていない属性 –

関連する問題