Mr.D
Mr.D

Reputation: 7893

Rails, model with column of integer array

I have added created new migration:

class AddColumnsToDiscipline < ActiveRecord::Migration
 def change
   add_column :disciplines, :days, :integer, array: true
 end
end

Then I have run migration.

In my seed.rb file I have added this

t.disciplines.create(name: Company.name, days: [1, 2, 3])

After when I run rake db:seed, When I run my rails console all created models days attribute has nil value. Whad did I miss?

Upvotes: 5

Views: 10317

Answers (2)

Sonalkumar sute
Sonalkumar sute

Reputation: 2575

try this with default option

add_column :disciplines, :days, :integer, array: true, default: [] 

in your migration file and then

run rake db:seed

EDIT

Try as

add_column :disciplines, :days, :integer, array: true, default: '{}' 

and change create to create!

t.disciplines.create!(name: Company.name, days: [1, 2, 3])

If you are using strong parameters have you permitted days in your controller

Upvotes: 7

jon snow
jon snow

Reputation: 3072

This issue was opened in rails public repo. follow this.

rails 4-0-stable have come with that fix. Maybe you need to update the rails version :D.

Upvotes: 0

Related Questions