Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/61.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/4/wpf/14.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 rails3 jquery自动完成将参数传递到范围查询_Ruby On Rails - Fatal编程技术网

Ruby on rails rails3 jquery自动完成将参数传递到范围查询

Ruby on rails rails3 jquery自动完成将参数传递到范围查询,ruby-on-rails,Ruby On Rails,我正在努力找到Rails3jQuery自动完成gem问题的答案 我有两个模型。环境与财产 class Environment < ActiveRecord::Base has_many :properties name: string, envfile: string class Property < ActiveRecord::Base scope :with_environment_id, where(:environment_id => 14) be

我正在努力找到Rails3jQuery自动完成gem问题的答案

我有两个模型。环境与财产

class Environment < ActiveRecord::Base
  has_many :properties

 name: string, envfile: string

class Property < ActiveRecord::Base
  scope :with_environment_id, where(:environment_id => 14)  
  belongs_to :environment 

name: string, value: string, environment_id: integer
autocomplete工作正常,但它返回properties表中的所有记录。我只希望视图中显示属于环境的属性

如您所见,我在属性模型中定义了一个作用域,在该作用域中,我硬编码了一个有效的环境id,以使其按我所希望的方式工作

因此,我的问题是如何将环境id从视图/控制器传递回作用域

也许我从错误的角度处理这个问题

道歉,如果这是一个愚蠢的问题,但它已经困扰了我一整天

def get_autocomplete_items(parameters)
  super(parameters).where(:user_id => current_user.id)
end
class PropertiesController < ApplicationController
  autocomplete :property, :name, :scopes => [:with_environment_id]
  get :autocomplete_property_name, :on => :collection
def get_autocomplete_items(parameters)
  super(parameters).where(:user_id => current_user.id)
end