Skip to content

Polymorphic belongs to association

Alexandre Voyer edited this page Mar 8, 2016 · 5 revisions

Synopsis:

class Comment < ActiveRecord::Base
  belongs_to :commentable, :polymorphic => true, :inverse_of => :comments

  rails_admin do
    configure :commentable do
      # configuration here
    end
  end
end

# for info
class Team < ActiveRecord::Base
  has_many :comments, :as => :commentable, :inverse_of => :commentable
end

More here

Clone this wiki locally