0

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

Max Paprikas
  • 579
  • 6
  • 16
  • Can you share your database schema for those three models? – penner Oct 06 '15 at 23:18
  • Just a note, the convention for your join model would be CategoryCollection instead of Cat. – penner Oct 06 '15 at 23:20
  • Possible duplicate of [rails ActiveAdmin nested form has\_one accepts\_attributes\_for formtastic issue](http://stackoverflow.com/questions/8159884/rails-activeadmin-nested-form-has-one-accepts-attributes-for-formtastic-issue) – penner Oct 06 '15 at 23:27
  • @penner I've added schema. PS. even index page (admin/categories) fail to open without id in `cats` table. So I enable it. But edit still not work. About note - yeah, I know, Just remove everything to beat this without extra words. – Max Paprikas Oct 06 '15 at 23:37
  • About relevant issue: I do not need any possibility to edit nested fields. I need to assign records only. – Max Paprikas Oct 06 '15 at 23:47

0 Answers0