Rails deletes record on edit and not submit

…衆ロ難τιáo~ 提交于 2019-12-13 01:24:38

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/37031796/rails-deletes-record-on-edit-and-not-submit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!