sferik/rails_admin — pull request #2007 by fantgeass (2014-06-11 13:47:54+00:00)
Title: dependent_field for belongs_to

Dependent field for belongs_to association.

Example:

We have user with country/city.
User chooses country "Russia" and city field now contains all russian cities.
When user changes country to "France", city field will lost value and select list now contain all "France" cities.
~~~
class User < ActiveRecord::Base
belongs_to :country
belongs_to :city

rails_admin do
edit do
field :city do
dependent_field :country
associated_collection_scope do
country_id = bindings[:controller].params[:dependent_field_value]
Proc.new { |scope|
scope = scope.where(country_id: country_id) if country_id
}
end
end
end
end
end
~~~