AssociationType 与嵌套模型表单上的预期类型不匹配
在执行嵌套模型表单时,我遇到此异常:
ActiveRecord::AssociationTypeMismatch in RecipesController#update
Ingredient(#35624480) expected, got Ingredient(#34767560)
涉及的模型是配方和成分。食谱 has_many 并接受_nested_attributes_for :inredients,属于 :recipe。
当我尝试 _destroy (=1) 配方编辑/更新的嵌套成分表单上预先存在的成分之一时,出现此异常。
这没有多大意义,主要是因为关联类型符合预期(异常自己承认)。
更没有意义的是它在功能测试中工作得很好。
另外,如果我重新发布表单(通过更新时浏览器刷新),它有时会起作用。如果我重新启动(开发)网络服务器,它也将起作用。
有什么想法可能导致此问题,或者我应该寻找什么?
I'm getting this exception when doing a nested model form:
ActiveRecord::AssociationTypeMismatch in RecipesController#update
Ingredient(#35624480) expected, got Ingredient(#34767560)
The models involved are Recipe and Ingredient. Recipe has_many and accepts_nested_attributes_for :ingredients, which belongs_to :recipe.
I get this exception when attempting to _destroy (=1) one of the preexisting Ingredients on a nested Ingredient form for the Recipe Edit/Update.
This makes very little sense, mostly because the association types are as expected (by the exception's own admission).
What makes even less sense is that it works just fine in a functional test.
Also, it sometimes works if I re-post the form (via a browser refresh on Update). It also will work if I restart the (development) webserver.
Any ideas what might be causing this, or what I should be looking for?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这通常意味着“rails 未能成功重新加载一次”
在您的environment/xxx文件中,您可以将其更改为不重新加载,或允许其重新加载。
this usually means "rails failed to reload successfully once"
in your environment/xxx files you can change it to not reload, or allow it to reload.
有时可以通过添加正确的要求来解决此问题,从您的代码中使用该类的位置开始
This can sometimes be fixed by adding correct require's, start where the class is used in your code