Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Block syntax for has_many association.build

#502

With a has_many relationship, allows attributes to be set via a block, as in

client.addresses.build do |address|
  address.street = "Main Street"
  address.zip_code = 12345
  ...
end

Reported by Jason Dew · June 27th, 2008 @ 07:33 PM

State: resolved
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. wildchild
  2. Jason Dew
    Jason Dew

    that ticket is incomplete; this patch includes test cases

    June 27th, 2008 @ 07:45 PM

  3. Christian Weyer
    Christian Weyer

    +1 from me. Opening a block is the ruby way of doing things.

    The current hash-based method is very problematic, since you can't update attributes, which are protected from mass assignment.

    July 7th, 2008 @ 12:28 AM

  4. asceth
  5. Repository
    Repository

    (from [c6f397c5cecf183680c191dd2128c0a96c5b9399]) Add block syntax to HasManyAssociation#build. [#502 state:resolve]

    Signed-off-by: Pratik Naik

    http://github.com/rails/rails/co...

    July 14th, 2008 @ 02:55 AM

  6. Pratik
    Pratik
    • State changed from new to resolved

    July 14th, 2008 @ 03:00 AM

  7. Repository
    Repository

    (from [04f7ac59d23ccf1b4b29bac8d99f02e634001dee]) Add block syntax to HasManyAssociation#build. [#502 state:resolve]

    Signed-off-by: Pratik Naik

    http://github.com/rails/rails/co...

    July 15th, 2008 @ 11:57 PM

  8. Jeff Kreeftmeijer
    Jeff Kreeftmeijer
    • Tag cleared.
    • Importance changed from to Low

    Automatic cleanup of spam.

    November 7th, 2010 @ 04:55 PM