3

I am aware of t.text :tags, array: true, default: [] this syntax in migration to create an array of data type text. Can I do the same in the rails generator itself?

2 Answers 2

3

You can do this following as:

rails g scaffold Todo tags:array

And you can check migrate file which was generated:

class CreateTodos < ActiveRecord::Migration
  def change
    create_table :todos do |t|
      t.array :tags

      t.timestamps null: false
    end
  end
end
Sign up to request clarification or add additional context in comments.

Comments

0

You can use array itself if you use a supported database like postgresql

rails g resource Todo  tags:array

3 Comments

So this will be an array which can hold anything like ruby array?
Yes, but only in postgress and other databases where array data type is supported , not in mysql
it doesn't work for me. it says array data type is not recognized

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.