Rails在编辑时删除记录而不提交 [英] Rails deletes record on edit and not submit

查看:201
本文介绍了Rails在编辑时删除记录而不提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

具有以下关联:



锻炼has_many workout_sets through ...



workout_set has_many workout_steps through ...



编辑对象时,我遇到以下问题:

<1>转到 / model /:id / edit



2)检查数据库,一旦页面加载最高级别的属性(非嵌套的)从数据库中删除,一旦页面加载,但选择标记作为选择正确的值,就像在加载时刻数据是正确的一样。
$ b 3)不保存就退出页面(返回 / model /:id )会执行以下操作:


  • 3.1)由于未提交表单,因此不更新对象。 / li>
  • 3.2)给我一个没有它的主要属性的模型,而最深的嵌套属性保持不变。



我正在使用 simple_form 来处理嵌套模型。 PS:我可以根据需要提供代码。

解决方案

记录:



解决方案如下:

:force_non_association_create =>每个 link_to_add_association 都为true 。欲了解更多信息,请查阅


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.

解决方案

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

这篇关于Rails在编辑时删除记录而不提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆