Ruby on rails rails3 jquery自动完成将参数传递到范围查询
我正在努力找到Rails3jQuery自动完成gem问题的答案 我有两个模型。环境与财产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
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