Message from discussion
after_initialize/after_find misfeature
Received: by 10.35.37.18 with SMTP id p18mr2073193pyj.1185139560878;
Sun, 22 Jul 2007 14:26:00 -0700 (PDT)
Return-Path: <court3...@gmail.com>
Received: from py-out-1112.google.com (py-out-1112.google.com [64.233.166.179])
by mx.google.com with ESMTP id k36si2560738waf.2007.07.22.14.26.00;
Sun, 22 Jul 2007 14:26:00 -0700 (PDT)
Received-SPF: pass (google.com: domain of court3...@gmail.com designates 64.233.166.179 as permitted sender)
DomainKey-Status: good (test mode)
Received: by py-out-1112.google.com with SMTP id f31so3266905pyh
for <rubyonrails-core@googlegroups.com>; Sun, 22 Jul 2007 14:26:00 -0700 (PDT)
DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed;
d=gmail.com; s=beta;
h=domainkey-signature:received:received:message-id:from:to:in-reply-to:content-type:x-mailer:mime-version:subject:content-transfer-encoding:date:references;
b=Y5tPGFqroQuN/k6gLwLKSbobNRRbsygI5mi0lXPKmu6cABYcXRfv1yMm7R9hR0aKnwUc0HnLBuWEQurOaufu+9xI4aqteq/pIBLpz7C6ygjNR5uyQ8YnSoXgV3lCaVaB6WaMLIdbLvLXXy4MvohIiOB6Po0EG5ldxFuM84Eu74U=
DomainKey-Signature: a=rsa-sha1; c=nofws;
d=gmail.com; s=beta;
h=received:message-id:from:to:in-reply-to:content-type:x-mailer:mime-version:subject:content-transfer-encoding:date:references;
b=bWyGp0cZ20+YUtejY2tBHB4VIQEypVW98IMrmiSKWG09QHfwZNW+rrxsaZ7M6NPtgtFooK5tp8J9TjA0YV6XNSGqtrEfXYo4L6rwM8s4mP3ONpUeTG3GpkEZi+o8xVmNA+/rGaIpYpMntudS/jpCk4wiqgMbhBkx0qKHe8RWvBw=
Received: by 10.35.10.13 with SMTP id n13mr4789813pyi.1185139559877;
Sun, 22 Jul 2007 14:25:59 -0700 (PDT)
Return-Path: <court3...@gmail.com>
Received: from ?10.1.36.111? ( [32.144.62.69])
by mx.google.com with ESMTPS id x72sm5624249pyg.2007.07.22.14.25.57
(version=TLSv1/SSLv3 cipher=OTHER);
Sun, 22 Jul 2007 14:25:59 -0700 (PDT)
Message-Id: <325B903D-3F89-4D25-A352-23152826C043@gmail.com>
From: court3nay <court3...@gmail.com>
To: rubyonrails-core@googlegroups.com
In-Reply-To: <897e96cc0707221403w52bdf34ydb39665c8afc14d9@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
X-Mailer: iPhone Mail (1A543a)
Subject: Re: [Rails-core] Re: after_initialize/after_find misfeature
Date: Sun, 22 Jul 2007 14:25:04 -0700
References: <897e96cc0707220254l750943a2naeab8aaf02499...@mail.gmail.com> <ef46c93e0707221102q4d34cab8hf0e825aa0a651...@mail.gmail.com> <897e96cc0707221150k776ae7fbgdc6997670c04b...@mail.gmail.com> <2257a00b0707221314nab576ffmfc5e313896f70...@mail.gmail.com> <32DE829A-399A-4456-8E0F-9C6822753...@gmail.com> <897e96cc0707221403w52bdf34ydb39665c8afc1...@mail.gmail.com>
On Jul 22, 2007, at 2:03 PM, "Piers Cawley" <pdcaw...@bofh.org.uk>
wrote:
>
> On 22/07/07, court3nay <court3...@gmail.com> wrote:
>>
>>
>> On Jul 22, 2007, at 1:14 PM, "Damian Janowski" <damian.janow...@gmail.com
>>> wrote:
>>
>>>
>>> On 7/22/07, Piers Cawley <pdcaw...@bofh.org.uk> wrote:
>>>> def new
>>>> @customer = Customer.new
>>>> end
>>>>
>>>> That @customer is never going to be validated, but it does make
>>>> sense
>>>> for it to have its defaults (which belong in the model and not the
>>>> controller or the view) set correctly so that 'new.rhtml' doesn't
>>>> need
>>>> any knowledge of any default values when rendering the form.
>>>
>>> Really hear you on that one.
>>>
>>> If we need to deal with default values in a better way, why not
>>> something like...
>>>
>>> class Foo < ActiveRecord::Base
>>> default :attrib, :to => 1
>>> default :another_attrib, :to => :another_attrib_defaulter
>>>
>>> protected
>>> def another_attrib_defaulter
>>> # ...
>>> end
>>> end
>>>
>>> The second parameter being a hash for some readability and
>>> potentially
>>> for some more features...
>>>
>>> Thoughts?
>>
>> Does default belong in the schema as it is essentially a db
>> functionality?
>
> No it isn't. Consider the use case of the newly created 'template'
> object that's used by new.rhtml in some generic controller; this never
> goes near the database, but still needs to have its defaults correctly
> set.
>
Right, that's the point i was missing.. but couldn't you do that as an
overloaded reader?
def name
read_attribute[:name] || "default name"
end
I do like the idea of wrapping that functionality in your syntax as
above, makes it a little quicker
courtenay
> >