crowdint/rails3-jquery-autocomplete — Issue #126: How can I pull extra_data on a related model.
Author: konung
Created: 2011-12-20 21:49:45+00:00
State: open

Hello.

Just wondering if this is possible:

class Product < ActiveRecord::Base
has_many :product_restrictions
has_many :restrictions, :through => :product_restrictions
end

class Restriction < ActiveRecord::Base
has_many :product_restrictions
has_many :products, :through => :product_restrictions
end

class ProductRestriction < ActiveRecord::Base
belongs_to :product
belongs_to :restriction
end

I'm using autocomplete on the Product, but I would like to pull restriction data using :extra_data. So far - no luck. Is it even possible right now?

autocomplete :product, :vendor_number,
:extra_data => [:name, :total_stock],
:display_value => :autocomplete_label

I would like to do something like this

autocomplete :product, :vendor_number,
:extra_data => [:name, :total_stock, :restrictions[:code]],
:display_value => :autocomplete_label

( My alternative is to add some kind of observer in js and trigger ajax call based on the update to the auto complete - but it's an unnecessary second call - so just wondering if there is any way to do this.

Thanks.