Ich habe eine TabelleWie erstellt man ein multi-model tag_cloud mit einer Join-Tabelle?
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
deren beitreten Zweck ist es, eine tag_cloud Arbeit für mehrere Modelle zu machen. Ich habe dies in der application_controller
def tag_cloud
@tags = CombineTag.tag_counts_on(:tags)
end
Mein tag_cloud wie folgt aussieht:
<% 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 %>
Ich habe diese Zeile in der _form aller Modelle: <%= f.text_field :tag_list %>
combine_tags_helper
module CombineTagsHelper
include ActsAsTaggableOn::TagsHelper
end
Modelle
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
Bitte lassen Sie mich wissen, wenn Sie weitere Erklärung benötigen oder code helfen Sie mir helfen :)
Können Sie mir sagen In Kürze, welches genaue Verhalten willst du implementieren? –
Ich weiß, wie man eine tag_cloud mit einem Modell erstellt, aber ich kann nicht mit mehreren Modellen arbeiten, wenn ich unter Gewohnheiten und unter Zielen ein Tag namens "run" erstellt habe, das tag_cloud die Verwendung des Tags proportional darstellt. Hilft das @ArupRakshit? –
Können Sie mir etwas über den Anwendungsfall mitteilen? Warum brauchst du _join_table_ versuchen zu verstehen? –