Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 搜掠搜索有一个:通过(别名)_Ruby On Rails_Ruby_Ransack - Fatal编程技术网

Ruby on rails 搜掠搜索有一个:通过(别名)

Ruby on rails 搜掠搜索有一个:通过(别名),ruby-on-rails,ruby,ransack,Ruby On Rails,Ruby,Ransack,我正在尝试使用ransack搜索模型中具有一个关联的属性。 目前在我的模型中,我有: class SurveyResponse < ActiveRecord::Base belongs_to :course_schedule has_one :instructor, through: :course_schedule has_one :instructor_user, through: :instructor, foreign_key: "user_id", source:

我正在尝试使用ransack搜索模型中具有一个关联的属性。
目前在我的模型中,我有:

class SurveyResponse < ActiveRecord::Base
  belongs_to :course_schedule 
  has_one :instructor, through: :course_schedule
  has_one :instructor_user, through: :instructor, foreign_key: "user_id", source: :user 
在我的调查响应控制器中,我目前拥有:

def index
  @search_associations = [:course, :user]

  @q = SurveyResponse.where(corporation_id: @corporation.id).ransack(params[:q])

  @q.build_condition

  @survey_responses =  @q.result.includes(:course, :user, :course_schedule, :instructor, :instructor_user).order(created_at: :asc)

  @survey_responses = paginate(@q)
end

任何帮助、资源和指导都将不胜感激

我不认为你需要一个专门的洗劫者。我相信你的观点,在
搜索表单中
你只需做以下事情:

<%= f.search_field :instructor_user_name %>


另外,在您的控制器中,而不是
@survey\u responses=paginate(@q)
,我认为您需要
@survey\u responses=paginate(@survey\u responses)
,这样您就可以对响应进行分页,而不是对ransack对象进行分页(根据您使用的分页宝石,这可能是错误的)。

我认为您不需要专门的ransacker。我相信你的观点,在
搜索表单中
你只需做以下事情:

<%= f.search_field :instructor_user_name %>

另外,在您的控制器中,而不是在
@survey\u responses=paginate(@q)
中,我认为您需要
@survey\u responses=paginate(@survey\u responses)
,以便您可以对响应进行分页,而不是对ransack对象进行分页(根据您使用的分页宝石,这可能是错误的)