【发布时间】:2015-10-17 01:52:38
【问题描述】:
用户可以为习惯、目标、价值观和统计数据提交标签。
当用户点击tag_cloud 中的标签时,他会被重定向到带有该标签所有实例的主页,但出于某种原因,属于习惯的实例正在重复。
关于为什么会这样的任何想法?
pages_controller
@habits = current_user.habits.tagged_with(params[:tag])
habit.rb
class Habit < ActiveRecord::Base
belongs_to :user
acts_as_taggable
before_save :set_tag_owner
def set_tag_owner
# Set the owner of some tags based on the current tag_list
set_owner_tag_list_on(self.user, :tags, self.tag_list)
# Clear the list so we don't get duplicate taggings (hmmm what does this mean? I copied this code & comment from somewhere else)
# self.tag_list = nil
end
在 views/home.html.erb 中:<%= render @habits %> 在 routes.rb 中:root 'pages#home'。
我试图只发布相关的东西,但这里是 gist。
【问题讨论】:
标签: ruby-on-rails ruby tags