public
Rubygem
Description: rails multi-model forms made easy!
Homepage: http://jamesgolick.com/attribute_fu
Clone URL: git://github.com/giraffesoft/attribute_fu.git
Search Repo:
update README to reflect discard_if change


git-svn-id: http://svn.jamesgolick.com/attribute_fu/trunk@68 
80b79608-713f-0410-8737-d8c0d0c1b50c
james (author)
Sat Feb 16 13:19:26 -0800 2008
commit  d8d719e7ecb1b0c93df35a96c125c1ddd73bfebd
tree    452820da3e7affa4cb72cd42d9d10398b9bebfa2
parent  babe962e02bb2d9cfe46a146c83d49bf235de98b
0
...
77
78
79
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
81
82
...
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
0
@@ -77,6 +77,27 @@ Creating the add button is equally simple. The add_associated_link helper will d
0
   
0
 That's all you have to do to create a multi-model form with attribute_fu!
0
 
0
+== Discarding Blank Child Models
0
+
0
+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:
0
+
0
+ class Project < ActiveRecord::Base
0
+ has_many :tasks, :attributes => true, :discard_if => proc { |task| task.title.blank? }
0
+ end
0
+
0
+...or a symbol...
0
+
0
+ class Project < ActiveRecord::Base
0
+ has_many :tasks, :attributes => true, :discard_if => :blank?
0
+ end
0
+
0
+ class Task < ActiveRecord::Base
0
+ def blank?
0
+ title.blank?
0
+ end
0
+ end
0
+
0
+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.
0
 
0
 = Updates
0
 

Comments

    No one has commented yet.