私はhttp://railscasts.com/episodes/382の指示に従っています-タグ付けしてゼロからタグシステムを構築しています。すべてがうまく機能していますが、tag_cloudヘルパーではありません。tag_countsの検索中にデータベースエラーが発生します。
次の範囲:
#Picture.rb
class Picture < ActiveRecord::Base
attr_accessible :description, :title, :tag_list
has_many :taggings
has_many :tags, through: :taggings
#Because of the following I'm getting an error from the Posgresql (showed in "Database Error")
def self.tag_counts
Tag.select("tags.*, count(taggings.tag_id) as count").
joins(:taggings).group("taggings.tag_id")
end
end
Application_helper.rb
def tag_cloud(tags, classes)
max = tags.sort_by(&:count).last
tags.each do |tag|
index = tag.count.to_f / max.count * (classes.size - 1)
yield(tag, classes[index.round])
end
データベースエラー
ActiveRecord :: StatementInvalid in Pictures#index
PG::Error: column "tags.id" should appear in the GROUP BY clause or be used in an aggregate function
LINE 1: SELECT tags.*, count(taggings.tag_id) as count FROM "tags" I...
^
: SELECT tags.*, count(taggings.tag_id) as count FROM "tags" INNER JOIN "taggings" ON "taggings"."tag_id" = "tags"."id" GROUP BY taggings.tag_id