On Jul 22, 2007, at 2:03 PM, "Piers Cawley" <[EMAIL PROTECTED]>
wrote:
>
> On 22/07/07, court3nay <[EMAIL PROTECTED]> wrote:
>>
>>
>> On Jul 22, 2007, at 1:14 PM, "Damian Janowski" <[EMAIL PROTECTED]
>>> wrote:
>>
>>>
>>> On 7/22/07, Piers Cawley <[EMAIL PROTECTED]> 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
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Core" 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-core?hl=en
-~----------~----~----~----~------~----~------~--~---