Michael Pavling wrote:
> On 1 October 2010 07:19, Bob Smith <[email protected]> wrote:
>> Is there any way to delete blank records as part of the validation??
> 
> What do you mean "as part of the validation"? Which validation? What
> records do you want to delete? Why allow them to save if they're not
> valid?
> 
> There are lots of ways you can stop the errors though - it just
> depends which direction you want to approach it:
>  * You could add validation to the Person model to make birthday 
> mandatory.
>  * You could add a method to Person called "birthday" which returns
> the birthday attribute or a dummy date (you could call this method
> "birthday_for_sort" - to make it clear what its purpose is, and to
> maintain the AR method for )
>  * you could remove records from the people collection before the 
> sort_by:
>      @household.people.delete_if { |p| p.birthday.blank? 
> }.sort_by(&:birthday)
>  * you could add a fake dob value before the sort_by:
>      @household.people.each { |p| p.birthday = "1 Jan 1900" if
> p.birthday.bllank? }.sort_by(&:birthday)
> 
> and more ways to crack the nut...
> Some of them smell more than others - depends, as ever, on what you
> actually want to achieve... but maybe you can get some idea of how to
> sort your problem.
> 
> HTH

Sorry, not enough information.. again..

My view has 4 fields for new records: sex month, day, and year. It also 
has a new person link that creates as many new empty records as needed.
After the 'Save Changes' link is clicked, my controller then validates 
these fields and makes a birthday field using whatever is entered ( 
Sounds like I should put this action in the model ). The problem comes 
if a new person record is left without any data. It looks like the model 
isn't saving these empty records, but they are still in the 
@household.people collection, killing a call to sort_by. All this 
trouble to put the birthdays in order..

Thanks

Bob <[email protected]>
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to