Skip to content

Commit

Permalink
update README to reflect discard_if change
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.jamesgolick.com/attribute_fu/trunk@68 80b79608-713f-0410-8737-d8c0d0c1b50c
  • Loading branch information
james committed Feb 16, 2008
1 parent babe962 commit d8d719e
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions README
Expand Up @@ -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

Expand Down

0 comments on commit d8d719e

Please sign in to comment.