Search code examples
ruby-on-railsrails-admin

How can I increase the limit of drop box in rails admin gem


Hi I m stuck in a situation and I m unable to find a solution, there is a dropbox that displays the tags matched with the string entered but the limit is set for 30 as it displays 30 results only. I want it to increase it but I m unable to find where the limit is applied. here is the list of result limited to 30

the logs do return the query but I m unable to find it

Started GET "/admin/tag?associated_collection=tags&compact=true&current_action=update&source_abstract_model=video&source_object_id=7732&query=simula" for 127.0.0.1 at 2021-06-10 22:19:57 -0700
Processing by RailsAdmin::MainController#index as JSON
  Parameters: {"associated_collection"=>"tags", "compact"=>"true", "current_action"=>"update", "source_abstract_model"=>"video", "source_object_id"=>"7732", "query"=>"simula", "model_name"=>"tag"}
  Admin Load (0.7ms)  SELECT  `admins`.* FROM `admins` WHERE `admins`.`id` = 14 ORDER BY `admins`.`id` ASC LIMIT 1
  Video Load (0.4ms)  SELECT  `videos`.* FROM `videos` WHERE `videos`.`id` = 7732 ORDER BY `videos`.`id` ASC LIMIT 1
   (0.3ms)  SELECT COUNT(*) FROM `tags`
  Tag Load (1.2ms)  SELECT  `tags`.* FROM `tags` WHERE ((LOWER(tags.name) LIKE '%simula%') OR (LOWER(tags.ui_name) LIKE '%simula%')) ORDER BY tags.id desc LIMIT 30

can anyone please help me out, how may I increase the limit


Solution

  • You need to configure the field like this

    rails_admin do
      edit do
        field :tags do
          associated_collection_scope do
            proc do |scope|
              scope.limit(600)
            end
          end
        end
      end
    end
    

    But more importantly i discovered this searching on the rails_admin code, i tried searching for the string ' 30' on the rails admin gem folder and there were not that many results one had the limit.

    cd $(bundle show rails_admin)
    ag ' 30' | grep limit
    

    This returned

    lib/rails_admin/config/fields/association.rb:43:          associated_collection_scope_limit = (associated_collection_cache_all ? nil : 30)
    

    So i opened the file and found that the block of code that has that scoping is part of the configuration of all association fields on rails admin so i knew i could just add it to that particular field.