我正在使用名为'acts_as_votable'的宝石(https://github.com/ryanto/acts_as_votable) 现在,我正在尝试获取代码的特定记录。
用户:has_many代码
#fetching all the communities that current_user voted up.
@communities = current_user.get_up_voted(Community)
#Now I'm trying to retrieve all users who belongs to any of '@communities'
@users = @communities.???????(User)
@codes = users.codes
如何编码以检索代码?
答案 0 :(得分:1)
当您从所希望的社区中采样所有代码时,您可以从表用户中选择所需的条目。尝试:
@codes = []
@communities.each do |community|
@codes.concat(community.codes)
end
User.where(code: @codes).order(:active_at)
另见: http://guides.rubyonrails.org/active_record_querying.html