Typical cases that hit my head on first thought :

- When you want to set an attr_protected value based on value of other
fields. With my current patch, it won't work if you supply protected
value in mass assignment. Will patch it later.

- When you are using STI and have some fields whose default value
depends on type

- On a longer run, I'd love to make this useful for has_many :through
<< - but that's very far. In an idea world, I'd like to do something
like :

has_many :friendships do
  set_default_values :relation => "Family"
end
has_many :friends, :through => :friendships

And @model.friends << Something.create

Just a rough example. Achieving wouldn't really be simple. But if it's
done, it could be just awesome. This patch *might* be a first step
towards it.

Thanks,
Pratik

On 7/25/07, James H. <[EMAIL PROTECTED]> wrote:
>
> What kind of use cases are you expecting where this sort of behavior
> is desirable?  I think I'm coming up short on experience to imagine
> one.
>
> James H.
>
> On Jul 24, 9:30 pm, Pratik <[EMAIL PROTECTED]> wrote:
> > Just starting a new thread so that it's easy to follow.
> >
> > I just submitted a patch at trac to add a new class method called
> > "set_default_values" ( not a great name I think ), which lets you do
> > all kinds of crazy stuff with setting default values.
> >
> > This ticket is athttp://dev.rubyonrails.org/ticket/9093and example
> > pastie is athttp://pastie.caboo.se/81925
> >
> > It also lets you make use of other attributes ( set by supplying
> > attributes to Model.new call or even those set by set_default_values
> > call ) in setter method/proc.
> >
> > If people like this approach, I'll add tests to patch, else will just
> > close the ticket :)
> > --
> > Cheers!
> > - Pratikhttp://m.onkey.org
>
>
> >
>


-- 
Cheers!
- Pratik
http://m.onkey.org

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to