为什么我不能这样做:
class CreateModels < ActiveRecord::Migration
def self.up
create_table :fruit do |t|
t.array :apples
end
end
end
是否有其他方法可以使数组(“apples”)成为 Fruit 类实例的属性?
最佳答案
在 Rails 4 中并使用 PostgreSQL,您实际上可以在数据库中使用数组类型:
迁移:
class CreateSomething < ActiveRecord::Migration
def change
create_table :something do |t|
t.string :some_array, array: true, default: []
t.timestamps
end
end
end
关于ruby-on-rails - 为什么我不能在 Rails 的表格中创建一个数组作为列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6603743/