activeadmin has_one select from collection to update related foregn_key

Viewed 320

Can't find a solution a week along, please help Here I have 2 models

Item.rb

class Item < ActiveRecord::Base
  has_one :specs_group, class_name: Spec, :dependent => :nullify
  attr_accessible :specs_group_attributes
  accepts_nested_attributes_for :specs_group, update_only: true
end

Spec.rb

class Spec < ActiveRecord::Base
  belongs_to :item
  attr_accessible :item_id
end

Here is admin/item.rb

ActiveAdmin.register Item do
  form do |f|
    f.inputs "Specs group" do
      f.has_many :specs_group do |s|
        s.input :title, as: :select, collection: Spec.roots.map { |a| [a.title] }
      end
    end
    f.actions
  end
end

I want to choose element from Spec collection and update corresponding Spec item. With code above I can choose from dropdown list, but it updates Spec's title or creates new. It's a Rails 3.2 app.

0 Answers
Related