在rails上的ruby中插入null值的列值

时间:2022-05-29 17:08:29

I want to customize the value inserted in the column in the controller and i want to insert a null value in it. In this way :

我想自定义插入控制器列中的值,我想在其中插入一个空值。通过这种方式 :

@users.to = null

1 个解决方案

#1


3  

I believe you want:

我相信你想:

@user.to = nil

You may have to run a migration to ensure the column allows NULL values:

您可能必须运行迁移以确保该列允许NULL值:

change_column :users, :to, :string, :null => true

#1


3  

I believe you want:

我相信你想:

@user.to = nil

You may have to run a migration to ensure the column allows NULL values:

您可能必须运行迁移以确保该列允许NULL值:

change_column :users, :to, :string, :null => true