Rails: Adding migration to add an array (default empty)

后端 未结 3 937
小蘑菇
小蘑菇 2020-12-24 12:14

I\'m trying to add a column called share to one of my resources. The idea is that users can upload documents and share them with other (specific) users, and the array contai

3条回答
  •  青春惊慌失措
    2020-12-24 12:39

    Rails 4 the PostgreSQL Array data type

    In terminal

    $ rails generate migration AddTagsToProduct tags:string
    

    Migration file:

    class AddTagsToProduct < ActiveRecord::Migration
      def change
        add_column :products, :tags, :string, array: true, default: []
      end
    end
    

    https://coderwall.com/p/sud9ja/rails-4-the-postgresql-array-data-type

提交回复
热议问题