[英]Rails migration of an array inside a model doesn't work
我正在尝试创建一个包含一些数组的模型。 通过此命令创建迁移文件后:
rails g model post poster_first_name:string poster_first_name:string email:string poster_id:integer poster_profile_pic:string message:string post_type:string comments:text
创建了迁移文件,我将迁移文件修改为如下所示(尝试生成post_type
和comments
数组):
class CreatePosts < ActiveRecord::Migration
def change
create_table :posts do |t|
t.integer :poster_id, null: false, default: 0
t.string :poster_first_name, default: ""
t.string :poster_last_name, default: ""
t.string :poster_profile_pic, default: ""
t.string :message, null: false, default: ""
t.string :post_type, array: true, default: []
t.text :comments, array: true, default: []
t.timestamps null: false
end
end
end
此迁移文件看起来正确。 我运行rake db:migrate
这是我的架构的样子:
create_table "posts", force: :cascade do |t|
t.integer "poster_id", default: 0, null: false
t.string "poster_first_name", default: ""
t.string "poster_last_name", default: ""
t.string "poster_profile_pic", default: ""
t.string "message", default: "", null: false
t.string "post_type", default: "--- []\n"
t.text "comments", default: "--- []\n"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
所以基本上rails并不明白这些字段是数组。 我尝试了很多不同的东西。 但没有运气。 我将不胜感激任何帮助。 (这可能是一个菜鸟问题)
请检查以下答案: Ruby on Rails:在表单中提交数组
所以你可以理解如何使用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.