0

我有这门课。

用户:

class User < ActiveRecord::Base
  attr_accessible :email, :name
  has_many :berichten
end

类别:

class Category < ActiveRecord::Base
  attr_accessible :name
  has_many :berichten
end

贝里希滕:

class Berichten < ActiveRecord::Base
  attr_accessible :bericht, :user
  belongs_to :user
  belongs_to :category
end

之后我创建了项目。

但是当我去

http://localhost:3000/admin/berichtens 

我看到这条消息出现:

undefined method `user_id_contains' for #<MetaSearch::Searches::Berichten:0x007f72300bc8f0>

那可能是因为 berichten 是一个嵌套路由,看起来像这样:

Tamara::Application.routes.draw do
  ActiveAdmin.routes(self)

  devise_for :admin_users, ActiveAdmin::Devise.config

  resources  :users

  resources :category do 
     resources :berichten
  end 
 end

如何解决这个问题?

罗洛夫

编辑 1:您可以在这里找到整个源代码树:https ://github.com/roelof1967/tamara_site/tree/admin_section

编辑 2:这里是开发日志:https ://gist.github.com/3933601

编辑 3:这里是控制器:https ://gist.github.com/3937461

4

2 回答 2

4

由于我是 1 级用户,所以我无法对上述问题发表评论。请也分享您的相关控制器代码。问题出在控制器中。

于 2012-10-23T06:39:29.687 回答
1

您的 berichtens 表没有 user_id 和 category_id 字段: https ://github.com/roelof1967/tamara_site/blob/admin_section/db/schema.rb#L49-54

创建一个迁移文件

add_column :berichtens, :user_id, :integer
add_column :berichtens, :category_id, :integer
于 2012-10-24T01:06:19.767 回答