Current_user有许多最喜爱的社区。最喜欢的社区可以通过这个获取。如何获取所有关联的记录?
@communities = current_user.get_up_voted(Community)
然后每个社区都有很多这样的话题。
社区的has_many:Community_topics
Community_topic belongs_to的:社区
现在,我怎么能获取所有被属于CURRENT_USER最喜爱的社区主题?
我想这
@communities = current_user.get_up_voted(Community)
@community_topics = Community_topics.where(:community_id => @communities).page(params[:page]).order("last_active_at DESC")
但我得到这个错误:(
NameError (uninitialized constant UsersController::Community_topics):
这是错字问题?试试这个'CommunityTopic.where(“community_id in(?)”=> @ communities.collect(&:id))' – Amar 2013-04-30 06:00:14
@Amar谢谢。现在我有这个错误:('Mysql2 ::错误:未知的列community_topics.community_id在(?)在哪里子句' – MKK 2013-04-30 06:03:29
@Amar请问我请正确的代码? – MKK 2013-04-30 06:14:45