Is it possible (I've not currently found a way) to have the select dropdown for a belongs_to filter the available collection to the user.
For example. When editing and order which belongs_to an address, the dropdown would only show addresses that belong to the user.
I believe you can extend Field::BelongsTo and override candidate_resources to do this.
Admittedly this should be much easier. I've encountered this problem myself.
FWIW, I just pushed fishbrain/administrate-field-belongs_to_search to tackle the problem with the select drop down containing way too many records on belongs_to fields. It uses selectize to create a type-ahead search.
It might solve your problem too, @tomgatzgates. Feel free to try it out! Will publish it to RubyGems soon.
@klaseskilson this is great. Thank you!
The administrate-field-belongs_to_search gem is published now: https://rubygems.org/gems/administrate-field-belongs_to_search
I tried to build my customized field class, but ran into a problem that the field object does not have the owner resource object.
https://github.com/thoughtbot/administrate/blob/e6ff1d6040a39de23330836312ecf6f8b12fcd70/lib/administrate/page/base.rb#L20
the dropdown would only show addresses that belong to the user.
It would be difficult because Field:BelongsTo has no way to get the owner resource user even if I extend and override candidate_resources.
Is there any suggested solution?
I found _form.html.erb has resource which I need.
I wrote custom field like this: https://gist.github.com/kuboon/cc57c3372669320112abd9044771c1de
It seems like this issue has two solutions, so I鈥檓 going to close this for now.
Please open an new issue if that鈥檚 not the case!
Thank you @klaseskilson for your gem administrate-field-belongs_to_search, exactly what I found missing in Administrate !
Thank you @kuboon !!
Most helpful comment
I found
_form.html.erbhas resource which I need.I wrote custom field like this: https://gist.github.com/kuboon/cc57c3372669320112abd9044771c1de