我正在使用投票宝石acts_as_votable。这仅仅是为了解释,我的问题不仅仅是一个'关于宝石的问题'。如果你有相同情况的任何例子,但另一个“穿衣” - 没有问题。
用两个词我想加上投票和帖子。但这并不容易,因为Vote类来自模块。所以我只能通过调用ActsAsVotable::Vote
来访问它。并做一些类似的事情
@posts = Post.where(user_id: user.id).includes(:vote)
导致错误:
Association named 'vote' was not found on Post; perhaps you misspelled it?
问题:有没有办法从外部模块的类中预加载数据?
这可能会奏效:
@posts = Post.where(user_id: user.id).includes(:votes_for)