Search code examples
ruby-on-railsformssimple-formcocoon-gem

Rails deletes record on edit and not submit


Having the following associations:

Workout has_many workout_sets through ...

workout_set has_many workout_steps through ...

When editing an object I'm experiencing the following issue:

1) go to /model/:id/edit

2) checking the db, once the page loads the top level attributes (the non-nested ones) are deleted from the db once the page loads, but the select marks as selected the correct values, as if in the moment of the load the data was correct.

3) leaving the page without saving (returning to /model/:id) does the following:

  • 3.1) don't update the object, due to no form is submitted.
  • 3.2) leave me with a model without it's primary properties, while the deepest nested attributes remain unchanged.

I'm using cocoon and simple_form to handle nested models. Is it something on Rails I'm missing out?

P.S: I can provide code if needed.


Solution

  • For the record:

    The solution is as simple as:

    :force_non_association_create => true on each link_to_add_association. For more information check this