Routing Error for a model with a join_table and has_many :through in RailsAdmin

独自空忆成欢 提交于 2019-12-05 10:33:21

Check all the CategoryProduct objects have foreign keys: category_id and product_id.

CategoryProduct.all.each {|c| raise("Repair #{c.id}") unless c.category && c.product}

Dec 21 update:

How i've installed brand new Rails 3.2.9 with Category, Product and CategoryProduct. Model's relationship code is identical, RailsAdmin with default settings.

And it works with no any problems!

I decided to test my hypothesis. I think maybe when you went from the HABTM to the HM2HM you have missed (forgot) to reestablish key column ID for CategoryProduct which is now not just a join-model, but an independent entity.

So, routing error like:

No route matches {:action=>"show", :model_name=>"category_product", :id=>nil, :controller=>"rails_admin/main"}

can be result of missing id.

Well I disabled CategoryProduct's id field manually (def id; nil; end).

and yes it is:

No route matches {:action=>"show", :model_name=>"category_product", :id=>nil, :controller=>"rails_admin/main"}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!