Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion after_initialize/after_find misfeature
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
court3nay  
View profile  
 More options Jul 22 2007, 5:25 pm
From: court3nay <court3...@gmail.com>
Date: Sun, 22 Jul 2007 14:25:04 -0700
Local: Sun, Jul 22 2007 5:25 pm
Subject: Re: [Rails-core] Re: after_initialize/after_find misfeature
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



 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.