我正在使用acts_as_taggable_on gem:https ://github.com/mbleigh/acts-as-taggable-on
我正在尝试在某些帖子上显示标签,但它会引发错误:
undefined method `tag_counts_on' for #<Array:0x007fa5d4ac3088>
看法:
<% tag_cloud @vote_feed_items.tag_counts_on(:tags).order('count desc').limit(15), %w[a b c] do |tag, css_class| %>
<%= link_to tag.name, tag_path(tag.name), class: css_class %>
<% end %>
控制器:
@user = User.find(params[:id])
@vote_feed_items = @user.vote_feed
用户模型:
def vote_feed
Micropost.unscoped.from_microposts_voted_for_by(self)
end
微邮模型:
def self.from_microposts_voted_for_by(user)
find_by_sql("select m.* from microposts m
join (SELECT voteable_id, updated_at FROM votes WHERE voter_id = #{user.id} AND voteable_type = 'Micropost') z on z.voteable_id=m.id
order by z.updated_at desc")
end
find_by_sql 是否返回一个数组?如果是这样,我需要用不同的方式写这个吗?