active_admin/formtastic ignoring polymorphic associations

Posted by James Maskell on Stack Overflow See other posts from Stack Overflow or by James Maskell
Published on 2011-11-24T17:47:28Z Indexed on 2011/11/24 17:50 UTC
Read the original article Hit count: 467

I'm currently having trouble with the form for a polymorphic association in active_admin in Ruby on Rails.

I have three models set up: offices, companies and users. Both companies and users can own an office. My models are set up as follows:

class Office < ActiveRecord::Base
  belongs_to :ownable, :polymorphic => true
end

class User < ActiveRecord::Base
  has_many :offices, :as => :ownable
end

class Company < ActiveRecord::Base
  has_many :offices, :as => :ownable
end

active_admin doesn't allow me to edit the owner on its forms, but does show it correctly on the index and show pages (including links to the company or user).

I've tried playing with formtastic to manually create the form but have not had any luck - the "ownable" fields just get ignored and everything else renders properly.

To be clear: I want to be able to edit the owner of the Office model on the new and edit fields in active_admin.

Can anyone offer any help? :)

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about polymorphic-associations