On Wed, Jan 14, 2009 at 8:26 PM, Pardee, Roy <[email protected]> wrote: > > Hey All, > > I find I'm writing a ton of nearly identical model methods to support mass > creation/update of child objects (a la the 'complex forms' series of > railscasts). Stuff like: > > def existing_child_attributes=(updated_kids) > children.each do |kid| > unless kid.new_record? > atts = updated_kids[kid.id.to_s] > if atts > kid.attributes = atts > kid.save > else > children.delete(kid) > end > end > end > end > > And likewise for a new_child_attributes= method. > > I'd like to write these methods once generically & call the generic versions > from the various models where I need to do this. But it seems that helper > methods aren't visible from within a model (right?). Where can I put these > generic methods so that they're visible from my models? I'm using rails > 2.0.2.
You may want to check out the attribute_fu plugin: http://github.com/giraffesoft/attribute_fu/commits/master This wraps up this pattern cleaner than I could in my vain attempts. It also provides some view helpers for displaying the models. -- Brandon -------------------------------------------------------------------------------- Training by Collective Idea: Ruby on Rails training in a vacation setting http://training.collectiveidea.com – San Antonio, TX – Jan 20-23 --~--~---------~--~----~------------~-------~--~----~ 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 [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-talk?hl=en -~----------~----~----~----~------~----~------~--~---

