From d8d719e7ecb1b0c93df35a96c125c1ddd73bfebd Mon Sep 17 00:00:00 2001 From: james Date: Sat, 16 Feb 2008 21:19:26 +0000 Subject: [PATCH] update README to reflect discard_if change git-svn-id: http://svn.jamesgolick.com/attribute_fu/trunk@68 80b79608-713f-0410-8737-d8c0d0c1b50c --- README | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/README b/README index 35ac0d1..7d06420 100644 --- a/README +++ b/README @@ -77,6 +77,27 @@ Creating the add button is equally simple. The add_associated_link helper will d That's all you have to do to create a multi-model form with attribute_fu! +== Discarding Blank Child Models + +If you want to show a bunch of blank child model forms at the bottom of your form, but you only want to save the ones that are filled out, you can use the discard_if option. It accepts either a proc: + + class Project < ActiveRecord::Base + has_many :tasks, :attributes => true, :discard_if => proc { |task| task.title.blank? } + end + +...or a symbol... + + class Project < ActiveRecord::Base + has_many :tasks, :attributes => true, :discard_if => :blank? + end + + class Task < ActiveRecord::Base + def blank? + title.blank? + end + end + +Using a symbol allows you to keep code DRYer if you are using that routine in more than one place. Both of those examples, however, would have the same effect. = Updates