_tags.html.erb
#Version 1 (Just lists out habits tags)
<% tag_cloud Habit.tag_counts, %w{s m l} do |tag, css_class| %>
<%= link_to tag.name, tag_path(tag.name), class: css_class %>
<% end %>
#Version 2
<% tag_cloud(@tags, %w(css1 css2 css3 css4)) do |tag, css_class| %>
<%= link_to tag.name, { :action => :tag, :id => tag.name }, :class => css_class %>
<% end %>
How can we get it where it list's out the current_user's habits AND goals, valuations, quantifieds? f.text_field :tag_list
is in the _form of each of these four models, which are also separate tables in the database.
I also added the below code to each of the four models. Here's is how it looks for valuations:
Helper
module ValuationsHelper
include ActsAsTaggableOn::TagsHelper
end
Controller
class ValuationController < ApplicationController
def tag_cloud
@tags = Valuation.tag_counts_on(:tags)
end
end
and for the User Model
User.tag_counts_on(:tags)
acts_as_tagger
acts_as_taggable
I'm using the acts-as-taggable-on gem, which I implemented from railscasts. Please let me know if you need any further code or explanation =]
Use the method with in the gem: acts_as_tagger in the User model to set up tags specific to the user. Example for acts_as_taggable_on gem docs:
In Your Case you will need to set up a join table that includes the ids of: Habits, Goals, Valuations and Quantifieds and then you should be able to create a variable to call the tag count on that table or individual set up each Habits, Goals, Valuations and Quantifieds in your views for a specific user. Either way it should look something like this:
UPDATE ATTEMPT
I tried migrating this:
but I got
undefined method 'valuation_id' for #<ActiveRecord::
I don't know ifhas_many
andbelongs_to
is enough to join the models I'm going to assume yes.Then what do I do with
@tags = YourModel.tag_counts_on(**context**)
? What does context mean? Does this go in _tags.html.erb? If so would it look like this:Create a model called
Tagalicious
.Since you want it in the sidebar put this in the application_controller:
Then in the helper:
Then in the model:
tag_cloud:
Hopefully that will clarify some things. I can't figure out how to make this line in your various models
<%= f.text_field :tag_list %>
point to theTagalicious
model.This is something we can go over in chat if you want or maybe try another question for that specific problem.