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.

Nested attribute accessors should ignore new records with truthy _delete key

#1861

Currently when you supply a _delete attribute on new nested records, it will be passed through to the actual model's build method and raise an UnknownArgumentError there.

In my opinion those records should simply be ignored, so that you can delete newly added records the same way that you delete existing ones without much JS or controller magic.

Reported by Pascal Ehlert · February 3rd, 2009 @ 04:49 PM

State: committed
Milestone: none
Assigned to: Michael Koziarski Michael Koziarski
Importance: none

Activity

  1. Eloy Duran
    Eloy Duran

    I would suggest to change the test test_should_remove_delete_key_from_arguments_hash_of_new_records to use '0' for the 'delete' key. Right now the record is rejected because delete has a truthy value, if you use '0' it will build and actually test what you intended to.

    Other then that I agree with the patch.

    February 3rd, 2009 @ 05:55 PM

  2. Eloy Duran
    Eloy Duran

    Arg, don't mind the formatting you get the point :)

    February 3rd, 2009 @ 05:58 PM

  3. DHH
    DHH
    • Milestone cleared.

    February 3rd, 2009 @ 06:34 PM

  4. Pascal Ehlert
    Pascal Ehlert

    Haha yes, I've been pretty tired when I did the patch. Thanks for the review and please find attached the updated version.

    February 3rd, 2009 @ 06:47 PM

  5. Eloy Duran
    Eloy Duran

    I have added some documentation and fixed a few whitespace errors. I'm a whitespace fanatic :)

    +1 The patch indeed tests the expected behaviour.

    February 4th, 2009 @ 08:27 AM

  6. Pascal Ehlert
    Pascal Ehlert

    Excellent, thanks a lot. I thought it would be obvious that a _delete key on new records rejects them, but it's certainly good to clearly state it in the documentation.

    Where have you found a whitespace error? I'm using TextMate with two spaces indentation, so there shouldn't be any. I suppose we just have a different idea of how it should be done here, because I'm usually careful with whitespaces as well. ;-)

    Thanks.

    February 4th, 2009 @ 10:27 AM

  7. Eloy Duran
    Eloy Duran

    The Rails source in general uses no spaces at all for empty lines. Textmate, however, adds spaces up-to the current indentation level. I myself prefer Textmate's style, but we should follow the general Rails convention.

    The “whitespace errors” I mentioned were around your test method :-)

    February 4th, 2009 @ 10:42 AM

  8. Pascal Ehlert
    Pascal Ehlert

    Totally agree and having no meaningless characters in the code does actually make more sense to me.

    February 4th, 2009 @ 10:51 AM

  9. Repository
    Repository
    • State changed from new to committed

    (from [455a7633dbdb295de828eb2657433d47d85eb0bc]) Nested attribute accessors should ignore new records with truthy _delete key.

    Signed-off-by: Michael Koziarski michael@koziarski.com [#1861 Nested attribute accessors should ignore new records with truthy _delete key state:committed] http://github.com/rails/rails/co...

    February 6th, 2009 @ 12:48 AM