Look into using callbacks, e.g. after_create or before_create (define
the methods and they get fired as you''d expect)
You could check for the presence of the category id in such a
callback, and then do your key stuff.
On Aug 29, 7:01 pm, Ben Johnson
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:> I appreciate any help you can give me on this.
>
> Say you have categories and products. Category has many products. So you
> do the following
>
> c = Category.new
> p = c.products.build
>
> p.category_id is already set. Say you had an attribute called
"key" for
> products. How would you get key to be automatically set to whatever you
> want when the product is built off of a category?
>
> Thanks!
> --
> Posted viahttp://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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---