I have a join table
create_table "combine_tags", force: true do |t|
t.integer "user_id"
t.integer "habit_id"
t.integer "valuation_id"
t.integer "goal_id"
t.integer "quantified_id"
end
whose purpose is to make a tag_cloud work for multiple models. I put this in the application_controller
def tag_cloud
@tags = CombineTag.tag_counts_on(:tags)
end
My tag_cloud looks like this:
<% tag_cloud(@tags, %w(css1 css2 css3 css4)) do |tag, css_class| %>
<%= link_to tag.name, tag_path(tag), :class => css_class %>
<% end %>
# or this depending on which works:
<% tag_cloud CombineTag.tag_counts, %w[s m l] do |tag, css_class| %>
<%= link_to tag.name, tag_path(tag.name), class: css_class %>
<% end %>
I have this line in the _form of all the models: <%= f.text_field :tag_list %>
combine_tags_helper
module CombineTagsHelper
include ActsAsTaggableOn::TagsHelper
end
models
class CombineTag < ActiveRecord::Base
belongs_to :habit
belongs_to :goal
belongs_to :quantified
belongs_to :valuation
belongs_to :user
acts_as_taggable
end
class Habit < ActiveRecord::Base # Same goes for other models
has_many :combine_tags
acts_as_taggable
end
Please let me know if you need further explanation or code to help you help me :)
run
under habits & under goals that the tag_cloud would represent the tag's usage in proportion. Does that help @ArupRakshit? – Lovett