1👍
✅
As a commenter already noted, probably You want a polymorphic associations. Consider this example:
class Vote < ActiveRecord::Base
belongs_to :voteable, polymorphic: true
end
class User < ActiveRecord::Base
has_many :votes, as: :voteable
end
class Product < ActiveRecord::Base
has_many :votes, as: :voteable
end
More info here:
http://guides.rubyonrails.org/association_basics.html#polymorphic-associations
Source:stackexchange.com