I have 3 models Category
, Collection
and Cat
Here is my associations:
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
Trying to assign fields with formtastic (ActiveAdmin):
ActiveAdmin.register Category do
form do |f|
f.semantic_errors
f.input :collection
f.inputs
f.actions
end
end
/edit page gives me following error:
undefined method `collection_id' for #<Category:0x007f8590b4a768>
How can I assign records with this relation? Is it possible?
Update. Here is the schema
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
Here is the source code (a bit modified) https://bitbucket.org/Paprikas/testrelation/overview