Can I share tags between 2 models?

I'm trying this gem but there is a situation where 2 models should share tags (so if one is created on model1, it should be available on model2).

Is this possible or should I create a model that allows me to keep tags for both models in a single place?

Example

class Hikes < ActiveRecord::Base
  # Name
  # Date
  # Hikers[*]
  # ...
  acts_as_taggable_on :event_types
end

class Events < ActiveRecord::Base
  # Name
  # Date
  # Note
  acts_as_taggable_on :event_types
end

I would like to share event_types "group" of tags between the two models. Expecially because I would like to create a something similar to the stackoverflow tag field (so with tag count to see how many times it has been used). Obviusly the tags_count should be shared between the two models.

Note: The Hike is actually an event (that's why they share the same group of tags) that is handled differently through the application because there are more things that I have to handle.

Answers


Your question is very incomplete.

Assuming that you have ActiveRecord models for the two "models" and the tags, this structure could work:

class A < ActiveRecord::Base
  has_many :tags
end

class B < ActiveRecord::Base
  has_many :tags
end

class Tag < ActiveRecord::Base
  belongs_to :a
  belongs_to :b
end

Need Your Help

Java regex library with recursion support

java regex recursive-regex

I am looking for a Java regexp lib with support for recursion, like:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.