Ruby on Rails - create an array column in ruby on rails - ruby on rails tutorial - rails guides - rails tutorial - ruby rails
- An array column is supported by PostgreSQL.
- Rails will automatically convert a PostgreSQL array to a Ruby array, and vice-versa.
Create a table with an array column:
create_table :products do |t|
t.string :name
t.text :colors, array: true, default: []
end
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team
Adding an array column to an existing table:
add_column :products, :colors, array: true, default: []
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team
Adding an index for an array column:
add_index :products, :colors, using: 'gin'