如何使新模型属性显示在活动管理仪表板中?

How to make new model attributes show in active admin dashboard?

我正在 Rails 开发一个注册应用程序,我正在使用 active admin 来管理它。添加到模型的新属性未显示在活动管理员中。

我决定为其中一个模型添加一个属性,并将其添加到 db 文件夹中。然后我 运行 db:migrate.

但是,新属性没有出现在管理员视图中。

这是我创建文件中的代码:

    class CreateRegistrations < ActiveRecord::Migration[5.0]
       def change
    create_table :registrations do |t|
       t.string :first_name
       t.string :last_name
       t.string :gender
       t.string :email
       t.string :nationality
       t.string :religion
       t.date :birthdate
       t.string :phone
       t.string :streetname
       t.string :city
       t.string :state
       t.string :zip
       t.boolean :need_ride
       t.string :has_spouse
       t.string :spouse_name
       t.string :english_level
       t.text :expectations
       t.string :length_of_stay
       t.text :exact_length
       t.integer :volunteer_partner
       t.boolean :matched

  t.timestamps
       end
    end
end

我已将最后一个属性- :matched 添加到控制器和管理模型中的参数和允许的参数。

它仍然没有出现。

有什么想法、建议吗?

提前致谢。

这是因为当您第一次创建 registration table 时,迁移 CreateRegistrations 已经 运行。 运行迁移后,如果您更改该迁移文件并再次 运行 db:migrate,它将看不到您对该迁移文件所做的更新。

要添加新属性,您应该通过运行以下命令创建一个新的迁移文件:

rails generate migration AddMatchedToYourModel matched:boolean

它应该创建一个新的迁移文件。然后 运行 rails db:migrate 再次