In the Rails_admin wiki, they describe how the binding area can work:
config.model Team do
field :players do
associated_collection_cache_all false
associated_collection_scope do
team = bindings[:object]
Proc.new { |scope|
scope = scope.where(league_id: team.league_id) if team.present?
scope = scope.limit(30).reorder('players.position DESC')
}
end
end
end
However, they also mention:
Also note that the scope takes into account the saved version of the record, not counting any unsaved changes that you might have made in the edit form. If you change the team championship, you will still see players from the old league until you save.
What is the best way to make this work for new, unsaved records too? Therefore, when I change the league in the form, the players will be updated accordingly, without saving the record.
source
share