Skip to main content

[Administrate] Autocomplete on 'foo: Field::BelongsTo'

Gems / Libraries • Asked by Nelson Casanova

Hello,

I'm currently doing some tests using Administrate to see if the functionality can be shaped in a way that is convenient for me... Some things have been quite easy and for the most part satisfactory, like arranging things in different ways, implementing rich text editing and such...

Right now I'm wondering if its possible to better the default implementation for BelongsTo what happens is you get a dropdown that calls data from the child table... So for the following schema...

  • Posts (id, title, category_id) - Categories (id, name)

...you will get Administrate to give you a dropdown of category names on creating a new post, thats fine if you have only 5 categs, but if you have 1000 then its gonna be a long scrolling to get the one you need. So again, I'm left here wondering if its some solution/gem that can be implemented to have a autocomplete field that can search on the child table for the desired value. Or maybe this functionality its built-in and I dont even know about it... =)

Regards!


I know you can use an administrate custom field to customize the form field. There are some gems out there to help make that easier but I can't remember the name of the one that does this.

This one isn't quite right since it seems like it's only for belongs to, but it's almost exactly what you want: https://github.com/fishbrain/administrate-field-belongs_to_search


oh! sweeeet! thats just the thing! I owe you a pint of guinness


Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 24,647+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.