3

I created a model in my Rails app and realized after some time that I had forgotten to add some attributes, and later added them via a generated migration.

I now realize that the order of the attribute columns in schema.rb is the order that they will appear in a generated resource view in ActiveAdmin.

I want to reorder the columns when I view that model in ActiveAdmin, and the only way I have thought to do so is by changing the column order in the database.

I have looked here and here, and attempted to run a database migration using change_table or change_column. This had no resulting change.

This is migration I ran, which had no result:

class Reordercolumn < ActiveRecord::Migration[5.0]
  def up
    change_table :student_details do |t|
      t.change :exact_length, :text, after: :length_of_stay
      t.change :returned_home, :boolean, after: :spouse_name
      t.change :has_spouse, :boolean, after: :expectation
    end
  end
end

Looking to view attribute columns in ActiveAdmin in a particular order, I ran a database migration to change columns, but the migration is not reordering the columns.

Vasilisa
  • 4,604
  • 3
  • 20
  • 25
dbate
  • 127
  • 13

1 Answers1

2

You need to reorder columns in ActiveAdmin? Let's do it in corresponding admin/student_detail.rb file

index do
  selectable_column
  column :exact_length
  column :returned_home
  column :has_spouse
end

show do
  attributes_table do
    row :title
    row :returned_home
    row :has_spouse
  end
end

More info about customizing index and show views you can find in the docs

Vasilisa
  • 4,604
  • 3
  • 20
  • 25