![](/img/trans.png)
[英]How do I re-order tabular data within rails so that the most recent data appears at the top?
[英]How do I re-order table columns in a Rails app?
我在我的 Rails 應用程序中創建了一個模型,一段時間后意識到我忘記添加一些屬性,后來通過生成的遷移添加了它們。
我現在意識到schema.rb
屬性列的順序是它們出現在 ActiveAdmin 中生成的資源視圖中的順序。
當我在 ActiveAdmin 中查看該模型時,我想對列重新排序,我認為這樣做的唯一方法是更改數據庫中的列順序。
我看過這里和這里,並嘗試使用change_table
或change_column
運行數據庫遷移。 這沒有產生任何變化。
這是我運行的遷移,沒有結果:
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
為了按特定順序查看 ActiveAdmin 中的屬性列,我運行了數據庫遷移以更改列,但遷移並未對列重新排序。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.