Rails Select 2不起作用

I use select2 to call an ajax search on my form. The form is unable to get response with my ajax, I tested at postman my Brand method, and it is able to return json, so I wonder if it is something wrong with my apllication.js or input? Previously I test with:

Sample input

<%= f.select :brand_id, Brand.all.collect {|x| [x.name, x.id]}, {include_hidden: false} %>

it is able search all data inside brand table.
products_controller.rb

  def brand
    @brands = Brand.select(:id, :name).where("name like :q", q: "%#{params[:q]}%")
    respond_to do |format|  
        format.json { render json: {brands: @brands.map { |e| {id: e.id, name: e.name} }}
      }
    end   end

input form

<%= f.hidden_field :brand_id, class: "brand-select", data: { source: dashboard_brand_path, placeholder: 'Search for a name' } %>

application.js

$( ".brand-select" ).select2({
    minimumInputLength: 1,
    placeholder: "Brand search",
    theme: "bootstrap",
    tags: [],
    ajax: {
        url: "/dashboard/brand",
        dataType: 'json',
        type: "GET",
        quietMillis: 50,
        id: function(obj) {
          return obj.id;
        },
        data: function (term) {
            return {
            q: params.term, // search term
            page: params.page
          };
        },
        results: function (data) {
            return {
                results: $.map(data, function (item) {
                    return {
                        name: item.name,
                        id: item.id
                    }
                })
            };
        }
    },
});

Thank for helping

<%= f.hidden_field :brand_id, class: "brand-select", data: { source: dashboard_brand_path, placeholder: 'Search for a name' } %>

You have Used hidden_field. I guess you should use

<%= f.select :brand_id, Brand.all.collect {|x| [x.name, x.id]}, {include_hidden: false}, class: 'brand-select', placeholder: 'Search for a name' %>