activeadmin_addons icon indicating copy to clipboard operation
activeadmin_addons copied to clipboard

selected_list will not link to models without an "id" column

Open schwern opened this issue 4 years ago • 0 comments

I've have a State table where the primary key is not :id, it is :abbr. It also has a :name column.

# db/migrate/create_states.rb
class CreateStates < ActiveRecord::Migration[6.1]
  def change
    create_table :states, id: false, bulk: true do |t|
      t.primary_key :abbr, :string, limit: 2
      t.string :name, null: false
      t.timestamps
    end
  end
end

# app/model/state.rb
class State < ApplicationRecord
end

# app/admin/states.rb
ActiveAdmin.register State do
  config.sort_order = 'abbr_asc'
end

I've made a selected list for them.

            f.input :state_ids,
              label: "States",
              as: :selected_list,
              order_by: "abbr_asc",
              fields: [:abbr, :name],
              wrapper_html: { title: "Restrict to these US states only." }

The searching works fine, but I cannot click on the shown states. There are no Javascript errors in console.

If I add a fake id column it works.

# app/model/state.rb
class State < ApplicationRecord
  attribute :id, type: :string
end

schwern avatar Aug 30 '21 22:08 schwern