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

时间:2019-01-09 20:52:57

标签: ruby-on-rails activeadmin

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

我决定将属性添加到其中一个模型中,并将其添加到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。

它仍然没有显示。

有什么想法,建议吗?

谢谢。

1 个答案:

答案 0 :(得分:1)

This is because the migration CreateRegistrations already ran, when you first create the registration table. After running a migration if you change that migration file and run db:migrate again it won't see the update you did to that migration file.

To add the new attribute you should create a new migration file by running the following command:

rails generate migration AddMatchedToYourModel matched:boolean

It should create a new migration file. And then run rails db:migrate again.

相关问题