这是我的category.rb
attr_accessible :name has_many :category_products do def with_products includes(:product) end end has_many :products,:through => :category_products
这是我的产品.rb
attr_accessible :name,:description,:price,:vendor_ID,:image,:category_IDs belongs_to :vendor has_many :category_products do def with_categorIEs includes(:category) end end has_many :categorIEs,:through => :category_products
这是我的category_product.rb
attr_accessible :product_ID,:category_ID,:purchases_count belongs_to :product belongs_to :category valIDates_uniqueness_of :product_ID,:scope => :category_ID
这是我的routes.rb
mount Railsadmin::Engine => '/admin',:as => 'rails_admin' resources :categorIEs resources :vendors do resources :products end authenticated :user do root :to => 'home#index' end root :to => "home#index" devise_for :users resources :users
当我在查看Railsadmin时单击CategorIEs时,出现此错误:
ActionController::RoutingError at /admin/categoryMessage No route matches {:action=>"show",:model_name=>"category_product",:ID=>nil,:controller=>"rails_admin/main"}
当我点击category Products时,我也会收到此错误
ActiveRecord::StatementInvalID at /admin/category_productMessage sqlite3::sqlException: no such column: category_products.desc: SELECT "category_products".* FROM "category_products" ORDER BY category_products. desc liMIT 20 OFFSET 0
Railsadmin中的所有其他链接用于我的其他“普通”(即非HMT)模型.
可能是什么导致了这个?
谢谢.
编辑1
对于它的价值,这里是我点击Rails管理员内部的“类别”时的日志:
CodeRay::Scanners Could not load plugin nil; falling back to :textCodeRay::Scanners Could not load plugin nil; falling back to :textStarted GET "/admin/category?_pjax=%5Bdata-pjax-container%5D" for 127.0.0.1 at 2012-12-20 22:23:38 -0500Processing by Railsadmin::MainController#index as HTML Parameters: {"_pjax"=>"[data-pjax-container]","model_name"=>"category"} category Load (0.3ms) SELECT "categorIEs".* FROM "categorIEs" liMIT 6 User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."ID" = 1 liMIT 1 category Load (0.2ms) SELECT "categorIEs".* FROM "categorIEs" ORDER BY categorIEs.ID desc liMIT 20 OFFSET 0 categoryProduct Load (0.2ms) SELECT "category_products".* FROM "category_products" WHERE "category_products"."category_ID" = 2 Rendered /.rvm/gems/ruby-1.9.3-p194@apt-605/gems/rails_admin-0.3.0/app/vIEws/rails_admin/main/index.HTML.haml within layouts/rails_admin/pjax (29.4ms)Completed 500 Internal Server Error in 43msCodeRay::Scanners Could not load plugin nil; falling back to :textCodeRay::Scanners Could not load plugin nil; falling back to :textStarted GET "/admin/category" for 127.0.0.1 at 2012-12-20 22:23:40 -0500Processing by Railsadmin::MainController#index as HTML Parameters: {"model_name"=>"category"} category Load (0.3ms) SELECT "categorIEs".* FROM "categorIEs" liMIT 6 User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."ID" = 1 liMIT 1 category Load (0.2ms) SELECT "categorIEs".* FROM "categorIEs" ORDER BY categorIEs.ID desc liMIT 20 OFFSET 0 categoryProduct Load (0.2ms) SELECT "category_products".* FROM "category_products" WHERE "category_products"."category_ID" = 2 Rendered /.rvm/gems/ruby-1.9.3-p194@apt-605/gems/rails_admin-0.3.0/app/vIEws/rails_admin/main/index.HTML.haml within layouts/rails_admin/application (30.5ms)Completed 500 Internal Server Error in 251ms
编辑2
这是一个错误的gist of the full trace.我正在使用gem better_errors,因此跟踪看起来不像标准的Rails跟踪错误.但数据是一样的.
编辑3
这是我的3个模型的架构:
categoryProducts
# == Schema information## table name: category_products## product_ID :integer# category_ID :integer# purchases_count :integer default(0)# created_at :datetime not null# updated_at :datetime not null
类别
# == Schema information## table name: categorIEs## ID :integer not null,primary key# name :string(255)# created_at :datetime not null# updated_at :datetime not null
产品
# == Schema information## table name: products## ID :integer not null,primary key# name :string(255)# description :string(255)# price :float# vendor_ID :integer# created_at :datetime not null# updated_at :datetime not null# image :string(255)
请注意,categoryProduct没有主键字段.这是问题吗?
解决方法 检查所有categoryProduct对象是否有外键:category_ID和product_ID.categoryProduct.all.each {|c| raise("Repair #{c.ID}") unless c.category && c.product}
12月21日更新:
我如何使用category,Product和categoryProduct安装全新的Rails 3.2.9.模型的关系代码是相同的,Railsadmin具有默认设置.
它没有任何问题!
我决定测试我的假设.我想也许当你从HABTM转到HM2HM时,你错过了(忘了)重新建立categoryProduct的关键列ID,现在这不仅仅是一个连接模型,而是一个独立的实体.
所以,路由错误如:
No route matches {:action=>"show",:controller=>"rails_admin/main"}
可能是缺少身份的结果.
我手动禁用了categoryProduct的ID字段(def ID; nil; end).
是的它是:
No route matches {:action=>"show",:controller=>"rails_admin/main"}总结
以上是内存溢出为你收集整理的ruby-on-rails – 在RailsAdmin中具有join_table和has_many:through的模型的路由错误全部内容,希望文章能够帮你解决ruby-on-rails – 在RailsAdmin中具有join_table和has_many:through的模型的路由错误所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)