未定义的方法`collection_id'对于

时间:2015-10-06 23:13:39

标签: ruby-on-rails ruby-on-rails-4 activeadmin has-many-through formtastic

我有3个模型CategoryCollectionCat

这是我的协会:

class Category
  has_one :cat
  has_one :collection, through: :cat
end

class Collection
  has_many :cats
  has_many :categories, through: :cats
end

class Cat
  belongs_to :category
  belongs_to :collection
end

尝试使用formtastic(ActiveAdmin)分配字段:

ActiveAdmin.register Category do
  form do |f|
    f.semantic_errors

    f.input :collection

    f.inputs
    f.actions
  end
end

/编辑页面给出了以下错误:

undefined method `collection_id' for #<Category:0x007f8590b4a768>

如何分配具有此关系的记录?有可能吗?

更新。这是架构

&#13;
&#13;
ActiveRecord::Schema.define(version: 20151006174748) do

  # These are extensions that must be enabled in order to support this database
  enable_extension "plpgsql"
  enable_extension "hstore"

  create_table "categories", force: :cascade do |t|
    t.string  "name"
  end

  create_table "cats", force: :cascade do |t|
    t.integer "category_id"
    t.integer "collection_id"
  end

  add_index "cats", ["category_id"], name: "index_cats_on_category_id", using: :btree
  add_index "cats", ["collection_id"], name: "index_cats_on_collection_id", using: :btree

  create_table "collections", force: :cascade do |t|
    t.string "name"
    t.string "label"
  end

  add_foreign_key "cats", "categories"
  add_foreign_key "cats", "collections"
end
&#13;
&#13;
&#13;

这是源代码(有点修改) https://bitbucket.org/Paprikas/testrelation/overview

0 个答案:

没有答案