Ruby on rails rails中的嵌套搜索

Ruby on rails rails中的嵌套搜索,ruby-on-rails,ruby,postgresql,ruby-on-rails-4,nested,Ruby On Rails,Ruby,Postgresql,Ruby On Rails 4,Nested,我现在有一个用户,他是一个顾问,有很多项目 has_many :advisorizations, :dependent => :destroy has_many :projects, :through => :advisorizations 每个项目都有很多用户 has_many :projectizations, :dependent => :destroy has_many :users, :through => :projectizations 现在我想

我现在有一个用户,他是一个顾问,有很多项目

 has_many :advisorizations, :dependent => :destroy
 has_many :projects, :through => :advisorizations
每个项目都有很多用户

 has_many :projectizations, :dependent => :destroy
 has_many :users, :through => :projectizations
现在我想在curren_用户中搜索,即当前_用户是顾问的项目用户

current_user.projects.users
给出类似于#
@users=[]的“未定义的方法`users'的错误”
 @users = []   
 current_user.projects.each{|project| @users << project.users }

当前的| user.projects。每个{| project |@users您应该能够通过添加到advisors类中来实现这一点:

has_many :advisorizations, :dependent => :destroy
has_many :projects, :through => :advisorizations
has_many :projectizations, :through => :projects
has_many :users, :through => :projectizations

然后你应该能够做
current\u user.users
,尽管这可能会让人困惑

这只会给出一个项目数组(?)你会在{}中找到用户.project.users=>
当前用户是顾问的项目用户的用户
如何将它们全部放入@users变量中?这仍然只返回两个项目。这为nil:NilClass提供了一个“未定义的方法`链'”“.FYI user和advisor类是相同的..未定义的方法在哪里?在视图中?在controller@current_user.users行中,您可以发布nil:NilClass提取源的完整stacktraceundefined方法‘chain’(在第13行附近):11 12 13 14 15@users=current_user.users end end”