Value not registered: attribute name

Unable to complete this. I am using seed.rb + factory_girl to populate the rake db: seed database.

(I know that fixtures exist, but I want it to be done this way, this is just an example, the DB will be filled with complex association objects.)

My seed.rb:

require 'factory_girl_rails'
["QM","CDC","SI","QS"].each do |n|
  FactoryGirl.create(:grau, nome: n)
end

and my / factories / graus.rb

FactoryGirl.define do
  factory :grau do
    nome
  end
end

but when I ran:

rake db: seed

I get:

rake aborted!
Trait not registered: nome

Tasks: TOP => db:seed

Any clues?

+5
source share
1 answer

You need to add the default value for nome:

FactoryGirl.define do
  factory :grau do
    nome 'lorem'
  end
end
+16
source

All Articles