开发者

AssociationTypeMismatch with Expected Type on Nested Model Forms

开发者 https://www.devze.com 2022-12-31 05:57 出处:网络
I\'m getting this exception when doing a nested model form: ActiveRecord::AssociationTypeMismatch in RecipesController#update

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 f开发者_如何学Cine 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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消